New submission from 2106 Hyunwoo Oh <ohwp...@gmail.com>:
If you do the following: lists=[[]]*100 lists[1].append('text') print(lists[2]) you can see lists[2] contains 'text' even though it was appended to lists[1] in the text. A little more investigation with the id() function can show that the lists are shallowly copied when list multiplication occurs. I think this can confuse users when they try to use list multiplication to create nested lists, as they expected a deep copy to occur. ---------- components: Demos and Tools messages: 401625 nosy: ohwphil priority: normal severity: normal status: open title: Shallow copy occurs when list multiplication is used to create nested lists; can confuse users type: behavior versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45169> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com