[New-bugs-announce] [issue43157] Bug in methods of creating the list
sandeep kumar
report at bugs.python.org
Sun Feb 7 14:08:50 EST 2021
New submission from sandeep kumar <samrajput1143 at gmail.com>:
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
j+=1
print()
for a in range(d):
B[i][j]=data
print("{0}:{1}:{2}".format(i,j,B[i][j]),end=" ")
data+=1
i+=1
print()
for a in range(d):
B[i][j]=data
print("{0}:{1}:{2}".format(i,j,B[i][j]),end=" ")
data+=1
j-=1
print()
for a in range(d):
B[i][j]=data
print("{0}:{1}:{2}".format(i,j,B[i][j]),end=" ")
data+=1
i-=1
print()
d=d-2
print(d)
print(B)
if d==0:
B[int(A/2)][int(A/2)]=data
print(B[int(A/2)][int(A/2)])
print(B)
return B
##if i'm using different approach to create 2d list . Then i'm getting right output .
in above code i used B=[[0]*A]*A and getting wrong output . A is positive integer.
##If i'm using for i in range(A-1):
B.append([0]*A)
then i'm getting correct output.
but the 2d list generated using both the approach are same.
2d list from approach 1== 2d list from approach 2 ------->it is true
----------
messages: 386602
nosy: samrajput1143
priority: normal
severity: normal
status: open
title: Bug in methods of creating the list
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43157>
_______________________________________
More information about the New-bugs-announce
mailing list