What's the difference in Python? DP = [[0] * n] * n vs a list comprehension
n = 3
DP_1 = [[0] * n]  * n
DP_2 = [[for 0 for j in range(n)] for i in range(n)]

Some of my DP solutions are failing for DP_1 and it always passes for DP_2. What is the difference between the two?

Comments (1)