[issue24589] Wrong behavior for list of lists

2015-07-08 Thread Martin Panter
Changes by Martin Panter : -- stage: -> resolved status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsu

[issue24589] Wrong behavior for list of lists

2015-07-08 Thread Martin Panter
Martin Panter added the comment: This is how Python is meant to work; see . Unless there is something in the documentation that gave you the wrong impression, I suggest we close this. -- nosy: +v

[issue24589] Wrong behavior for list of lists

2015-07-08 Thread Bastiaan Albarda
Bastiaan Albarda added the comment: The * operator lets you use the same object multiple times, thereby saving resources. If you want unique objects use comprehension: >>> v = [[] for x in range(10)] >>> v[3].append(3) >>> v [[], [], [], [3], [], [], [], [], [], []] >>> v[3] += [3] >>> v [[],

[issue24589] Wrong behavior for list of lists

2015-07-08 Thread Zorceta
Zorceta added the comment: FYI: >>> ll = [[]]*10 >>> [id(l) for l in ll] [67940296, 67940296, 67940296, 67940296, 67940296, 67940296, 67940296, 67940296, 67940296, 67940296] -- nosy: +zorceta ___ Python tracker _

[issue24589] Wrong behavior for list of lists

2015-07-08 Thread Jos Dechamps
New submission from Jos Dechamps: After creating a list of lists, changing one element, leads to changes of all the elements: >>> v=[[]]*10 >>> v [[], [], [], [], [], [], [], [], [], []] >>> v[3].append(3) >>> v [[3], [3], [3], [3], [3], [3], [3], [3], [3], [3]] >>> >>> v=[[]]*10 >>> v [[], []