Zachary Ware <zachary.w...@gmail.com> added the comment:

For `list1`, you are creating three separate lists containing `0` contained by 
a fourth list.  For `list2`, you're creating a single list containing `0` 
contained by a second list, and then replicating the contents of that second 
list three times; thus `list2` actually contains the same list object three 
times.  You can compare the result of `[id(l) for l in list1]` with the same 
for `list2` to see this.

See point 2 here [1] and in this [2] FAQ for more information on this.

[1] https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
[2] https://docs.python.org/3/faq/programming.html#faq-multidimensional-list

----------
nosy: +zach.ware
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39403>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to