I have this code:
s = [64, 128]
a = [[]] * len(s)
print(a)
print(a[0])
a[0].append([1,2])
print(a)
If I run it, I get this:
[[], []]
[]
[[[1, 2]], [[1, 2]]]
So a
is a list of list, initialized with two empty lists.
I append the list [1,2]
to a[0]
, which, in my intentions, would be the first empty list.
I was expecting a
to be equal to [ [ [1,2] ], [] ]
.
Is there anyone who can help me?
1) Why did I get that [ [1,2], [1,2] ]
?
2) How can I assign [1,2]
to the first list in the list of lists a
?