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
This is a job for...the nested list comprehension!
[[0 for i in range(10)] for j in range(10)]
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.