Removing null items

sragsdale at my-deja.com sragsdale at my-deja.com
Tue Nov 30 20:05:41 CET 1999


So I've got a very simple desire: to remove all false (I.E. None, 0, '',
[]) items from a list.

As it is I've got this function which works fine, but it offends my
sight.  Is there any better (or at least different) way to do this?

#################################################################
# return non-null items from the first list
def foo(lst):
    rlist = []
    for i in lst:
        if i:
            rlist.append(i)
    return rlist


Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list