[issue43157] Bug in methods of creating the list

2021-02-07 Thread sandeep kumar


New submission from sandeep kumar :

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 
<https://bugs.python.org/issue43157>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 
<https://bugs.python.org/issue43157>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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

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  


#This code is for generating spiral matrix


##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

--

___
Python tracker 
<https://bugs.python.org/issue43157>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com