mat was initialized like this:
mat = [[0]*26]*5
The problem is that after an inner loop iteration all the rows in mat get changed the same but i clearly stated that only the ith row should change.
the problematic lines are the ones after the # comment
please help me :(
mat = [[0]*26]*5
The problem is that after an inner loop iteration all the rows in mat get changed the same but i clearly stated that only the ith row should change.
the problematic lines are the ones after the # comment
please help me :(
def fill_letters_matrix(mat, word_list): for i in range(len(mat)): for j, item in enumerate(word_list): if j != len(word_list)-1: if len(item)-i-1 < 0: continue #the jibrish in the second brackets works,so no need to dive in... mat[i][ord(item[len(item)-i-1])-ord("A")] += 1 else: mat[i][ord(item[len(item) - i-1]) - ord("A")] -= 1