[issue12951] List behavior is different

2011-09-10 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: See also http://docs.python.org/faq/programming.html#how-do-i-create-a-multidimensional-list -- nosy: +amaury.forgeotdarc ___ Python tracker ___

[issue12951] List behavior is different

2011-09-09 Thread Ezio Melotti
Ezio Melotti added the comment: I don't see where is the bug. If you do >>> lists = [[]] * 3 >>> lists [[], [], []] you are creating a list that contains 3 references to the same list, as you can see here: >>> lists[0] is lists[1] is lists[2] True >>> [id(l) for l in lists] [33714832, 3371483

[issue12951] List behavior is different

2011-09-09 Thread शंतनू
New submission from शंतनू : URL: http://docs.python.org/library/stdtypes.html Following example is given. >>> lists = [[]] * 3 >>> lists [[], [], []] >>> lists[0].append(3) >>> lists [[3], [3], [3]] Behavior is as follows. >>> a = [[]] * 3 >>> a [[], [], []] >>> a[0] = 1 >>> a [1, [], []] >>