
class GrowingList(list): def __setitem__(self, index, value): if index >= len(self): self.extend([None]*(index + 1 - len(self))) list.__setitem__(self, index, value)
用法:
>>> grow = GrowingList()>>> grow[10] = 4>>> len(grow)11>>> grow[None, None, None, None, None, None, None, None, None, None, 4]
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)