Removing None objects from a sequence

Arnaud Delobelle arnodel at googlemail.com
Fri Dec 12 14:36:12 EST 2008


alex23 <wuwei23 at gmail.com> writes:

> Rather than a list comprehension, use a generator expression:
>
> for item in (x for x in sequence if x is not None):
>    do_something(x)

I much prefer

for item in sequence:
    if x is not None:
        do_something(x)

-- 
Arnaud



More information about the Python-list mailing list