indexed assignment in list

Abdur-Rahmaan Janhangeer arj.python at gmail.com
Wed Jul 11 02:50:21 EDT 2018


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



More information about the Python-list mailing list