i have a list of tuples that i loop through in a simple for loop to identify tuples that contain some conditions.
mytuplist =
[(1, 'ABC', 'Today is a great day'), (2, 'ABC', 'The sky is blue'),
(3, 'DEF', 'The sea is green'), (4, 'ABC', 'There are clouds in the sky')]
I want it to be efficient and readable like this:
for tup in mytuplist:
if tup[1] =='ABC' and tup[2] in ('Today is','The sky'):
print tup
The above code does not work and nothing gets printed.
This code below works but is very wordy. How do i make it like the above?
for tup in mytuplist:
if tup[1] =='ABC' and 'Today is' in tup[2] or 'The sky' in tup[2]:
print tup