Wtf is wrong with Python ide


#1

I am getting correct output for A = 100 and B = 1 on my system’s Python and IntBit’s iDE is giving output 0 0 for the following code with same input, A = 100, B = 1

def uniquePaths(self, A, B):
a = [[0] * A] * B

        for i in range(len(a)):
            for j in range(len(a[i])):
                
                if i == 0 or j == 0:
                    
                    a[i][j] = 1
                else:
                    a[i][j] = a[i-1][j] + a[i][j-1]
        
        m = len(a) -1
        n = len(a[len(a)-1])-1
        return a[m][n]

#2

Hey, I tried your same code and it is getting accepted by IB ide. Also, if you want to create a 2d list in python, then you should not create it as a = [[0] * A] * B instead create it as
a=[[0 for x in range(A)] for y in range(B)]
To know why to use this kind of 2d list, please google “How to create 2d list in python”. The 2d list in your case is not actually a 2d list.