python数据结构之array用法实例

本文实例讲述了python数据结构之array用法,分享给大家供大家参考。具体方法如下:

import ctypes
class array:
def __init__(self, size):
assert size > 0, “array size must be > 0 ”
self._size = size
pyarraytype = ctypes.py_object * size
self._elements = pyarraytype()
self.clear(none)
def clear(self, value):
for index in range(len(self)):
self._elements[index] = value
def __len__(self):
return self._size
def __getitem__(self, index):
assert index >= 0 and index < len(self), "index must >=0 and =0 and

Posted in 未分类

发表评论