I get this error:
Traceback (most recent call last): File "C:/Python27/main.py", line 21, in matrix[1][1].append(2) IndexError: list index out of range
This is my code
file = open("C:\\Python27\\test.txt", "r")
s1 = file.read();
s2 = file.read();
matrix = [[0 for x in range(len(s1))] for x in range(len(s2))]
matrix[1][1].append(2)
print matrix[1][1]
len(s1) and len(s2) is larger than 5
I try using matrix[1][1] = 2 instead of matrix[1][1].append(2)but it won't work.
So what's my mistakes?
matrix[1][1].append(2)will certainly not work as you are trying to append to anintlen(s2)again.matrix = [ [0] * len(s1) ] * len(s2)