We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
@puneetkaur, are you sure you want to define your arr this way?
arr = [[0]* len(str1)]*len(str2) will actually give you a list with n same lists. Take a look:
arr = [[0] * 2]*2
print(arr)
[[0, 0], [0, 0]]
arr[1][1] = 1
print(arr)
[[0, 1], [0, 1]]
Sorry, if its irrelevant. Just I am new to python and faced this problem myself
Common Child
You are viewing a single comment's thread. Return to all comments →
@puneetkaur, are you sure you want to define your
arr
this way?arr = [[0]* len(str1)]*len(str2)
will actually give you a list with n same lists. Take a look:Sorry, if its irrelevant. Just I am new to python and faced this problem myself