[issue12597] List created by multiplication behaves different

2011-07-20 Thread R. David Murray
R. David Murray added the comment: I'm not sure what your example is trying to achieve, but the list(tuple(...)) looks redundant. Your initial example could be written: b = [[0] for i in range(3)] -- nosy: +r.david.murray ___ Python tracker

[issue12597] List created by multiplication behaves different

2011-07-20 Thread Сергій Загорія
Сергій Загорія added the comment: So the workaround is for i in range(len(list_generated)): list_generated[i]=list(tuple(list_generated[i])) -- ___ Python tracker ___ ___

[issue12597] List created by multiplication behaves different

2011-07-20 Thread Sandro Tosi
Sandro Tosi added the comment: Hi, no it's not a bug :) What you actually get with [[0]]*3 is a list of 3 references to the same list, [0]: >>> a = [[0], [0], [0]] >>> b = [[0]]*3 >>> for i in a: print(id(i)) ... 139807725184032 139807725300280 139807725300520 >>> for i in b: print(id(i)) ..

[issue12597] List created by multiplication behaves different

2011-07-20 Thread Сергій Загорія
New submission from Сергій Загорія : Next code: def ill(row): row[1]=1 list_manual=[[0,0,0],[0,0,0],[0,0,0]] list_generated=[[0,0,0]]*3 ill(list_manual[1]) print(list_manual) ill(list_generated[1]) print(list_generated) Will output: [[0, 0, 0], [0, 1, 0], [0, 0, 0]] [[0, 1, 0], [0, 1, 0], [0