Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to search just for the first coordinate in a list of tuples? [duplicate]

Assuming I have a list of tuples like the following:
a = [('a','b'), ('c','d'), ('e','f')]
If I were to execute this line 'a' in a I would get False.
Is there a way to tell python "search the just for the first argument and accept whatever in the second"?
So that I could search something like ('a', *) in a and get True?

like image 676
Eliran Turgeman Avatar asked Dec 17 '22 13:12

Eliran Turgeman


1 Answers

Try using any (will return True if any of the elements is logically True) with map (to compare each first element in your tuples):

any(map(lambda x: x[0] == "a", a)))
like image 104
Gabio Avatar answered May 03 '23 19:05

Gabio