What way is the best to check an empty list?

Niklas Norrthon niklas.norrthon at hotmail.com
Thu Mar 26 03:27:54 EDT 2009


On 26 Mar, 08:18, Niklas Norrthon <niklas.norrt... at hotmail.com> wrote:

> But that can easily be achieved with the "or" operator as Michiel
> Overton notes elsewhere in this thread:

Michiel Overtoom was what I meant to write. My apologies!

> def some_function(arg, coll=None):
>     do_stuff(arg)
>     for item in coll or []:  # <= Here or is used to make None behave
> as an empty collection
>         do_more(arg, item)
>
> /Niklas Norrthon




More information about the Python-list mailing list