One thing first: No, this is not a question about why
someThing = [[]] * 10
someThing[0] = 1
gives [1,1,1,1,1,1,1,1,1,1].
My question is a bit more tricky: I do the folling:
x, y, z = ([[]] for i in range(3))
Now I assign a value:
x[0] = 1 # This works fine
And now another one:
x[1] = 2 # This does not work anymore
It gives me an IndexError: list assignment index out of range.
How can I make this work? As you can see, I want an empty list that contains 3 other lists to which i can append values.
Thanks in advance!
x[0] = 1actually does? It replaces one of your nested lists with the number 1. If you want to append values, you should useappend, not item assignment.