Python: initialize multi-dimensional list

后端 未结 8 1377
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 05:48

I want to initialize a multidimensional list. Basically, I want a 10x10 grid - a list of 10 lists each containing 10 items.

Each list value should be initialized to

8条回答
  •  独厮守ぢ
    2020-12-03 06:46

    An additional solution is to use NumPy library:

    import numpy as np
    
    zero_array = np.zeros((10, 10), dtype='int')
    

    This can be easily converted to a regular python list with the .tolist() method if necessary.

提交回复
热议问题