Issue
I am using Python. Assume that I have a list of tuples, A
, where each tuple, a
, contains 3 elements e.g. ('z', 1, 2)
and I also have a tuple with 2 element, t
, like (2, 3)
, I want to search for first element of a
e.g. 'z'
that the second element and the third element match with the first element and the second element of t
consecutively.
For example,
A = [('a', 1, 2), ('b', 2, 4), ('c', 2, 1), ('d', 1, 3), ('e', 1, 2)]
t = (1, 2)
Expected Output,
'a'
Thank you in advance.
Solution
def func(A,t):
for x,y in enumerate(A):
if t==(A[x][1],A[x][2]):
return A[x][0]
A = [('a', 1, 2), ('b', 2, 4), ('c', 2, 1), ('d', 1, 3), ('e', 1, 2)]
t = (1,2)
result = func(A,t)
print(result)
Answered By – Bolshoi Booze
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0