python / psf-infra-meta

Meta-repository for PSF backed or managed systems. Created mainly for the issue tracker :)
10 stars 9 forks source link

Found bug in the method of generating 2d list in python. #98

Closed samrajput1143 closed 3 years ago

samrajput1143 commented 3 years ago

def generateMatrix(A): #A is positive integer 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

rouilj commented 3 years ago

This is the wrong place to post a python bug. This tracker is for issues with the https://bugs.python.org tracker used for tracking python bugs.

matrixise commented 3 years ago

@ewdurbin Please, could you close this issue? Thank you,