[Tutor] For - if - else loop; print selective output
sbjaved at gmail.com
Wed Oct 24 18:43:15 CEST 2012
Let me modify this example:
a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
for i in a:
*b = i*
if (i == '25' or i == '26'):
print 'Not found'
This will output:
How do I print positive matches (*jimmy*) only and not (*Not found*). I
also want *Not found *to print only *once *if there are no positive matches.
On Wednesday, October 24, 2012, Saad Javed wrote:
> a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
> '21', 'cookies']]
> for i in a:
> if (i == '25' or i == '26'):
> print 'yes'
> print 'Not found'
> This prints:
> not found
> I want it to print "yes" for each positive match but nothing for a
> negative match. However if all matches are negative, I want it to print
> "Not found" once (That bit the code already does). I do I get it to print
> "yes" only in a mix result situation?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor