class defaultlist(list):

    def __setitem__(self, index, value):
        size = len(self)
if index >= size:
    self.extend(0 for _ in range(size, index + 1))
list.__setitem__(self, index, value)
Populating a list/array by index in Python?