Delete all items in the list

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Feb 27 01:37:06 CET 2009


En Thu, 26 Feb 2009 22:18:18 -0200, Chris Rebert <clp2 at rebertia.com>  
escribió:
> On Thu, Feb 26, 2009 at 4:08 PM, Peter Billam <peter at www.pjb.com.au>  
> wrote:
>> On 2009-02-26, Clarendon <jineu21 at hotmail.com> 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...
>
> A. That doesn't by itself remove all the 'a's, although it does remove
> all but 1 'a'
> B. That also removes all but one instance of *everything* in the list,
> not just 'a'
> C. That is lossy in that it completely loses the ordering of the  
> original list

I said the very same things!
There are other issues too, like this only works with hashable objects,  
but I've chosen exactly the same remarks and exactly in the same order!  
What a coincidence...

-- 
Gabriel Genellina




More information about the Python-list mailing list