python: 元组搜索列表

python: list of tuples search

这里需要一些帮助

num = [(1,4,5,30,33,41,52),(2,10,11,29,30,36,47),(3,15,25,37,38,58,59)]

如果最后 6 位数字位于 return 第一位数字。

示例 if 找到 10,11,29,30,36,47 return 2

您可以将 next 与条件生成器表达式一起使用:

num = [(1,4,5,30,33,41,52),(2,10,11,29,30,36,47),(3,15,25,37,38,58,59)]
search = 11

next(first for first, *rest in num if search in rest)
# 2

您可以使用 next 类似于用户的方法:

num = [(1,4,5,30,33,41,52),(2,10,11,29,30,36,47),(3,15,25,37,38,58,59)]
to_find = [10,11,29,30,36,47]

print(next(n for n, *nums in num if nums == to_find))

2