Here is the code with a TypeError in it. "List indices should be integers, not a list," although they are integers. I would be grateful if you could help me figure out what happened. I need to get the 7x5 matrix from the 7x5 tab of the source code with different values. Error on the last line.
lines = []
with open("text.txt") as f:
for line in f:
line = [int(x) for x in line if (x != ' ') and (x != '\n')]
lines.append(line)
f.close()
What I have after reading the file is a list of lists with numbers called "strings". These are integers. Not strings. How:
>> [[1, 2, 3...], [4, 5, 6...], [7, 8, 9...],[...]]
i = 1
j = 1
T = []
T.append(lines[0][0])
I did this to avoid IndexError(list out of range) on the last line ( i-1and stuff). Although, I do not think this is really a python-way. I would appreciate help on this.
for i in lines:
for j in lines:
T[i][j] = lines[i][j] + max(T[i][j-1], T[i-1][j])
. , , i, j int.