osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

indexed assignment in list


saw this snippet on the internet : why assigning by index propagates it all?

>>> a = [[1]] * 7
>>> a
[[1], [1], [1], [1], [1], [1], [1]]
 >>> a[0][0] = 2
>>> a
[[2], [2], [2], [2], [2], [2], [2]]

why not

[[1], [2], [2], [2], [2], [2], [2]]

?

thank you !
-- 
Abdur-Rahmaan Janhangeer
https://github.com/abdur-rahmaanj
Mauritius