What does E = [[0] * m] * n do exactly? I though it would give me an n x m list of lists of 0. I narrowed down the problem so the code has lines that are missing but I am trying to fill the table for edit distance which is in Chapter 6 of Algorithms by Dasgupta et al.
What I wanted to do with the for loop for i was to store the index number in the first column but I am puzzled.
def minDistance(self, word1: str, word2: str) -> int:
n = len(word1) + 1
m = len(word2) + 1
E = [[0] * m] * n
for i in range(1, n):
E[i][0] = i
print('\n'.join(['\t'.join([str(cell) for cell in row]) for row in E])
However, I got 11 which is the last index of i on the entire first column.
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0
I made a substitution to E = [[0] * m for _ in range(n)] following code from this question and got the right answer.
0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0 0
10 0 0 0 0 0 0 0 0 0 0
11 0 0 0 0 0 0 0 0 0 0