Delete all items in the list

Boris Borcic bborcic at gmail.com
Thu Feb 26 08:00:30 EST 2009


Chris Rebert wrote:
> On Thu, Feb 26, 2009 at 3:05 AM, Clarendon <jineu21 at hotmail.com> wrote:
...
>> 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?
> 
> There are several ways. I'd go with a list comprehension:

and for a couple other ways

while 'a' in L : L.remove('a')

L = filter('a'.__ne__,L)




More information about the Python-list mailing list