Delete all items in the list

Gabriel Genellina gagsl-py2 at
Fri Feb 27 01:27:26 CET 2009

En Thu, 26 Feb 2009 22:08:26 -0200, Peter Billam <peter at>  

> On 2009-02-26, Clarendon <jineu21 at> wrote:
>> Hi. This must be a simple command but I just can't find it in the
>> Phthon manual. How do I delete all items with a certain condition from
>> a list? For instance: > L=['a', 'b', 'c', 'a']
>> I want to delete all 'a's from the list.  > But if L.remove('a')
>> only deletes the first 'a'.  How do you delete all 'a's?
> L2 = list(set(L))
> works for me...

For a very strange definition of "works":

py> L = ['a','b','c','a','j','b','z','b','a']
py> L2
['a', 'c', 'b', 'z', 'j']
py> L2 = list(set(L))
py> L2
['a', 'c', 'b', 'z', 'j']

I still see an 'a', there are things missing, and the order is totally  

Gabriel Genellina

More information about the Python-list mailing list