gpt4 book ai didi

python - 如果等于 groups[*][0],其中 groups 是元组数组?

转载 作者:行者123 更新时间:2023-11-28 21:42:12 24 4
gpt4 key购买 nike

假设我有一个像这样的元组数组:

[('9a4591116d2c', 'production', None), ('a3270aa13595', 'production', '58cac003c0ed42196da3d50e'), ('puppetdb', 'production', 'test')]

我想查看某个值是否与任何元组的第一个值匹配。有没有一种快速的方法可以做到这一点,例如:

if node in groups[*][0]

最佳答案

if node in groups[*][0] 最接近的替代方法是

if node in (x[0] for x in groups):
...

但你也可以这样做

if any(node == first for first, *_ in groups):
...

关于python - 如果等于 groups[*][0],其中 groups 是元组数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44006640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com