如何在Python中搜索元组列表
问题描述:
所以我有一个这样的元组列表:
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.
因此,如果我执行search(53)
,它将返回2
So that if I do search(53)
it will return the index value of 2
有一种简单的方法吗?
答
[i for i, v in enumerate(L) if v[0] == 53]