Better solution

Mike C. Fletcher mcfletch at rogers.com
Tue Aug 20 17:29:14 CEST 2002


 >>> lst = ['', 'a', '', 'b', 'c', '', 'd']
 >>> filter( None, lst )
['a', 'b', 'c', 'd']
 >>>

HTH,
Mike

Bo M. Maryniuck wrote:
> Well, I want to throw away a _same_ garbage from a list with less of coding.
> This is current code, sure not the best ;-) Is any better solutions?
> 
> --------------8<------------------------
> lst = ['', 'a', '', 'b', 'c', '', 'd']
> map(lambda z:lst.pop(lst.index('')), range(0, lst.count('')))
> --------------8<------------------------
> 
> Now lst equals to ['a', 'b', 'c', 'd'].
> 


-- 
_______________________________________
   Mike C. Fletcher
   Designer, VR Plumber, Coder
   http://members.rogers.com/mcfletch/






More information about the Python-list mailing list