Checking the boolean value of a collection

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Fri Sep 12 18:07:37 CEST 2008


Marco Bizzarri a écrit :
(snip)
> I'm afraid this have another problem for me...
> 
> 
> emmebi at janitor:/var/local/zope28/porting/Products/PAFlow$ python2.3
> Python 2.3.5 (#2, Oct 18 2006, 23:04:45)
> [GCC 4.1.2 20061015 (prerelease) (Debian 4.1.1-16.1)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> def any(iterable): pass
> ...
>>>> any(x for x in [1, 2, 3])
>   File "<stdin>", line 1
>     any(x for x in [1, 2, 3])
>             ^
> SyntaxError: invalid syntax
> 
>>>> any([x for x in [1, 2, 3]])
>>>>
> 
> I mean, I'm afraid I can't use an expression like that without
> building a list... not at least in python2.3

Err... a list being an iterable, you just need any([1, 2, 3]).

But this wont be enough to solve your real use case, indeed.




More information about the Python-list mailing list