Remove empty strings from list

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Sep 15 11:20:32 CEST 2009


Dave Angel a écrit :
(snip)
> 
> As Chris says, you're modifying the list while you're iterating through 
> it, and that's undefined behavior.  Why not do the following?
> 
> mylist = line.strip().split(' ')
> mylist = [item for item in mylist if item]

Mmmm... because the second line is plain useless when calling 
str.split() without a delimiter ?-)

 >> mylist = line.strip().split()

will already do the RightThing(tm).




More information about the Python-list mailing list