[英]Check if namedtuple with value x exists in list
I want to see if a namedtuple exists in a list, similar to: 我想看看列表中是否存在一个namedtuple,类似于:
numbers = [1, 2, 3, 4, 5]
if 1 in numbers:
do_stuff()
is there a pythonic (or not) way to do this? 是否有pythonic(或非)方式这样做? Something like:
就像是:
namedtuples = [namedtuple_1, namedtuple_2, namedtuple3]
if (namedtuple with value x = 1) in namedtuples:
do stuff()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.