Lambda going out of fashion

Peter Otten __peter__ at web.de
Thu Dec 23 07:01:46 EST 2004


Alex Martelli wrote:

> if len(somecontainer) > 0:
> 
> instead of the obvious
> 
> if somecontainer:
> 
> so it's not as if pythonistas in general are blessed with some magical
> "redundancy avoidance spell"...
 
That is not always equivalent:

>>> z = Numeric.zeros(5)
>>> z
array([0, 0, 0, 0, 0])
>>> bool(z)
False
>>> len(z) > 0
True

Peter





More information about the Python-list mailing list