What way is the best to check an empty list?

Michiel Overtoom motoom at xs4all.nl
Thu Mar 26 00:19:47 CET 2009



On 25 Mar 2009, at 21:29 , Stef Mientki wrote:

> Now it would be nice to allow iteration over others too, like None .
>    a = None
>    for item in a :
>          do_something_with_item
>

I saw this technique used in CherryPy:

 >>> a=None
 >>> for item in a or []:
...    print item
...
 >>> a=[1,2,3]
 >>> for item in a or []:
...     print item
...
1
2
3
 >>>






More information about the Python-list mailing list