[issue45169] Shallow copy occurs when list multiplication is used to create nested lists; can confuse users

2021-09-10 Thread Steven D'Aprano
Steven D'Aprano added the comment: Oh, I forgot: this exact issue is also in the FAQs. https://docs.python.org/3/faq/programming.html#id46 -- ___ Python tracker ___

[issue45169] Shallow copy occurs when list multiplication is used to create nested lists; can confuse users

2021-09-10 Thread Steven D'Aprano
Steven D'Aprano added the comment: This is not a bug. No copy is made at all, neither shallow nor deep. This is described in the documentation for built-in types: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations and is similar to the issue in the FAQs:

[issue45169] Shallow copy occurs when list multiplication is used to create nested lists; can confuse users

2021-09-10 Thread 2106 Hyunwoo Oh
Change by 2106 Hyunwoo Oh : -- components: +Interpreter Core -Demos and Tools ___ Python tracker ___ ___ Python-bugs-list mailing

[issue45169] Shallow copy occurs when list multiplication is used to create nested lists; can confuse users

2021-09-10 Thread 2106 Hyunwoo Oh
New submission from 2106 Hyunwoo Oh : 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