Create an empty list in python with certain size

后端 未结 15 1759
有刺的猬
有刺的猬 2020-11-22 12:00

I want to create an empty list (or whatever is the best way) that can hold 10 elements.

After that I want to assign values in that list, for example this is supposed

15条回答
  •  星月不相逢
    2020-11-22 12:28

    One simple way to create a 2D matrix of size n using nested list comprehensions:

    m = [[None for _ in range(n)] for _ in range(n)]
    

提交回复
热议问题