Message401625
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. |
|
Date |
User |
Action |
Args |
2021-09-11 02:55:07 | ohwphil | set | recipients:
+ ohwphil |
2021-09-11 02:55:07 | ohwphil | set | messageid: <1631328907.83.0.354100007036.issue45169@roundup.psfhosted.org> |
2021-09-11 02:55:07 | ohwphil | link | issue45169 messages |
2021-09-11 02:55:07 | ohwphil | create | |
|