[issue43157] Bug in methods of creating the 2d list

2021-02-07 Thread Steven D'Aprano
Steven D'Aprano added the comment: There is also an FAQ about this: https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list See also: https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x By the way, for future bug reports,

[issue43157] Bug in methods of creating the 2d list

2021-02-07 Thread Steven D'Aprano
Steven D'Aprano added the comment: This is not a bug, it is working correctly, as designed. List multiplication does not *copy* the list, it replicates the reference to the same list object. So [[0]]*5 does not make five different sublists, but the same list repeated five times. Exactly the

[issue43157] Bug in methods of creating the 2d list

2021-02-07 Thread sandeep kumar
sandeep kumar added the comment: def generateMatrix(A): d=A-1 data=1 B=[[0]*A]*A for l in range(int(A/2)): i=l j=l for a in range(d): B[i][j]=data print("{0}:{1}:{2}".format(i,j,B[i][j]),end=" ") data+=1

[issue43157] Bug in methods of creating the 2d list

2021-02-07 Thread sandeep kumar
Change by sandeep kumar : -- title: Bug in methods of creating the list -> Bug in methods of creating the 2d list ___ Python tracker ___