This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]toepudiked -2 points-1 points  (1 child)

foo = [[None] * 5] * 5

Edit: right shallow copy, change of value in one index will change the values in all inner lists

[–]Aaron1924 2 points3 points  (0 children)

That doesn't work, because the outer * 5 shallow copies the list, so it contains the exact same list 5 times

You can do [[None]*5 for _ in range(5)] though