Better solution

Bo M. Maryniuck b.maryniuk at forbis.lt
Tue Aug 20 19:00:31 CEST 2002


On Tuesday 20 August 2002 17:39, Michael Hudson wrote:
> >   [x for x in lst if x]
> If you want to mutate the list, I'd say:
> lst[:] = filter(None, lst)
> is better than the monstrosity above.

Hmm... why the mostrosity? Is this example code is too ugly?
>>> [x for x in ['', 'a', 'b','!', 'c'] if x not in ['!', '']]       
['a', 'b', 'c']

Also what is [:]?

-- 
Regards, Bogdan

As far as the laws of mathematics refer to reality, they are not
certain, and as far as they are certain, they do not refer to reality.
                -- Albert Einstein





More information about the Python-list mailing list