Python List - “reserving” space ( ~ resizing)

后端 未结 4 1246
既然无缘
既然无缘 2021-01-03 22:42

I am given a list l and I want to do assignment:

l[index] = val

But there might be a case when the list is too small.

4条回答
  •  梦毁少年i
    2021-01-03 23:18

    Try this:

    def ResizeList(some_list, length, null_item = None): 
        return some_list + [null_item 
                            for item in range(length - len(lst))]
    

提交回复
热议问题