Reputation: 5
For example:
a = [[]]*50
I want only a[2]
to change to [2]
, but if I do a[2] = [2]
all the list become to [2]
, and I don't know how to do that
Upvotes: 0
Views: 38
Reputation: 163
>>> a = [[]]*50
>>> a
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], []]
>>> a[1] = [2]
>>> a
[[], [2], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], []]
>>> a[2] = [2]
>>> a
[[], [2], [2], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], []]
I hope I understood you correctly :)
Upvotes: 1