I have a problem with initialzing a 2D array in python. I want a 6x6 array, I did
arr = [[None]*6]*6
But when I do:
>&g
Using list comprehensions, you can say:
arr = [[None for x in range(6)] for y in range(6)]
Then you will have arr[1][2] = 10 working as expected. This is not a very normal thing to do, however. What are you going to use the nested lists for? There may be a better way. For example, working with arrays is made much easier with the numpy package.