sandeep kumar <samrajput1...@gmail.com> 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 <rep...@bugs.python.org>
<https://bugs.python.org/issue43157>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to