How to search a list of tuples in Python

hdx picture hdx · May 27, 2010 · Viewed 114.4k times · Source

So I have a list of tuples such as this:

[(1,"juca"),(22,"james"),(53,"xuxa"),(44,"delicia")]

I want this list for a tuple whose number value is equal to something.

So that if I do search(53) it will return the index value of 2

Is there an easy way to do this?

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · May 27, 2010
[i for i, v in enumerate(L) if v[0] == 53]