[BangPypers] Iterating list of tuples

Noufal Ibrahim noufal at gmail.com
Mon Jul 4 09:31:26 CEST 2011


Venkatraman S <venkat83 at gmail.com> writes:


[...]

> Right. I wrote this and then didnt send as the OP sounds like a n00b.

n00b (especially with the leet speak) is a tad pejorative. I think you
should not use the word here. 

> Btw, i got a  Q: why doesnt 'any' work in this case? Like...
> for tup in data:
>   if any(tup) > 5:
>     print 'greater'
>   else:
>     print 'lesser'

[...]

any expects an iterable of items with a truth value (True or
False). It will return True if any of the items are try. 

any(tup) will return True (since all the numbers in his tuple are non
zero and therefore True) so your condition is True > 5 (which ironically
evaluates to False on Python2.x) so it'll just print "lesser". 


-- 
~noufal
http://nibrahim.net.in

I am a deeply superficial person. -Andy Warhol


More information about the BangPypers mailing list