1. 如果希望实现一个和内建列表行为相似的序列,可以使用子类list
class CounterList(list):
def __init__(self, *args):
super(CounterList, self).__init__(*args)
self.counter = 0
def __getitem__(self, index):
self.counter += 1
return super(CounterList, self).__getitem__(index)
540

被折叠的 条评论
为什么被折叠?



