问题描述
我在python中使用过数组(既是list又是array.array),但我想知道如何在Python中实现像数组一样的数据结构。以下是查看其他语言的实现后的实现。请让我知道改进之处。
class my_array:
def __init__(self,length):
self.length = length
self.data = {}
def get(self,index):
return self.data[index]
def push(self,item):
self.data[self.length] = item
self.length += 1
return self.data
def pop(self):
last_item = self.data[self.length - 1]
del self.data[self.length-1]
self.length -= 1
return last_item
def insert(self,index,item):
self.data[index] = item
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)