Reputation: 675
I have a list like following
mylist = [('value1', 'value2', 'value3'), ('secval1', 'secval2', 'secval3')]
how do I see if the list contains 'value2'?
Upvotes: 20
Views: 41840
Reputation: 251146
similar to any()
, a solution that also supports short-circuiting :
>>> from itertools import chain
>>> mylist = [('value1', 'value2', 'value3'), ('secval1', 'secval2', 'secval3')]
>>> 'value2' in chain(*mylist)
True
proof that it short-circuits like any()
:
>>> it=chain(*mylist)
>>> 'value2' in it
True
>>> list(it) #part of iterable still not traversed
['value3', 'secval1', 'secval2', 'secval3']
Upvotes: 0