Removing null items

Gaetan Corneau Gaetan_Corneau at baan.com
Tue Nov 30 14:22:45 EST 1999


Take a look at the filter built-in function.

______________________________________________________
   Gaetan Corneau
   Software Developer (Quality Assurance Team)
   BaaN  Supply Chain Solutions  
   http://www.baan.com
   E-mail: Gaetan_Corneau at baan.com                  
   Tel: (418) 266-8252          
______________________________________________________
"Profanity is the one language all programmers know best"


> -----Original Message-----
> From: sragsdale at my-deja.com [mailto:sragsdale at my-deja.com]
> Sent: Tuesday, November 30, 1999 2:06 PM
> To: python-list at python.org
> Subject: Removing null items
> 
> 
> 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.
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list