Working in python 2.7.
I have two lists (simplified to make explanation more clear):
T = [[1, 0], [1, 0], [0, 5], [3, -1]]
B = [[1], [3], [2], [2]]
And three functions.
def exit_score(list):
exit_scores = []
length = len(list)
for i in range(0, length):
score = list[i][2] - list[i][0]
exit_scores.append(score)
return exit_scores
First I append the corresponding values of B to the corresponding lists in T:
def Trans(T, B):
for t, b in zip(T, B):
t.extend(b)
a = exit_score(T)
b = T
score_add(b, a)
Then, using the previously listed exit_score function. I subtract the the value in the list[2] position from the value in the list[0] position fore each list. I then append those results to another list (exit_scores).
Finally, I want to add the exit_scores (now a), to the original list.
So I use my score_add(b, a) function which is:
score_add(team, exit_scores):
for t, e in zip(team, exit_scores)
t.extend(e)
print team
If everything were working correctly, I would get an output like this:
[[1,0,1,0], [1,0,3,-2], [0,5,2,-2], [3,-1,2,1]]
Instead, I get a TypeError telling me that I can't iterate over an integer. But I've tried printing both a and b and both are in list form!
When I change the code to make sure that the exit scores are in a list:
def Trans(T, B):
es = []
for t, b in zip(T, B):
t.extend(b)
es.append(exit_score(T))
score_add(T, es)
The entire exit_scores list (es) is added to the end of the first list of T:
[[1, 0, 1, 0, 2, 2, -1], [1, 0, 3], [0, 5, 2], [3, -1, 2]]
For the life of me, I can't figure out what I'm doing wrong...