This toy example kind of represents a problem I have parsing data from a simulation package. I want to loop through a tuple and if a particular condition is met break the loop and return the time step that corresponds with that particular row. In the following example index 0 represents these time steps.
from random import randint
t = list(range(1,11))
a = [randint(1, 10) for i in range(0, 10)]
b = [randint(1, 10) for i in range(0, 10)]
c = [randint(1, 10) for i in range(0, 10)]
d = [randint(1, 10) for i in range(0, 10)]
e = [randint(1, 10) for i in range(0, 10)]
for i in zip(t,a,b,c,d,e):
print (i)
(1, 8, 5, 5, 3, 4)
(2, 2, 9, 5, 9, 1)
(3, 9, 3, 1, 6, 3)
(4, 9, 6, 7, 8, 3)
(5, 2, 7, 6, 8, 10)
(6, 6, 6, 8, 9, 6)
(7, 1, 8, 1, 8, 3)
(8, 1, 1, 1, 7, 5)
(9, 6, 10, 7, 4, 6)
(10, 5, 2, 6, 3, 8)
So lets say I want to return the first time step that the number 10 appears. Knowing that that is time step 5 and 10 is the last in the row I could hard code this:
for i in zip(t,a,b,c,d,e):
if i[5] == 10:
print(i[0])
5
I tried to solve the problem this way but I cant quite work out where I am going wrong, any pointers would be welcome.
for i in zip(t,a,b,c,d,e):
if i[1:] == 10:
print(i[0])