Re: Delete all items in the list

2009-02-28 Thread Terry Reedy
Steven D'Aprano wrote: Big Oh notation is good for estimating asymptotic behaviour, which means it is good for predicting how an algorithm will scale as the size of the input increases. It is useless for predicting how fast that algorithm will run, since the actual speed depends on those constan

Re: Delete all items in the list

2009-02-28 Thread Steven D'Aprano
Chris Rebert wrote: > Obviously that equivalence is true, but in this case I'm emphasizing > that it's even worse than that when constant factors are taken into > account. Big-O is nice in the abstract, but in the real-world those > constant factors can matter. > > In pure big-O, it is indeed O(M

Re: Delete all items in the list

2009-02-28 Thread Clarendon
Thank you very much for all your replies. I actually used the while loop as the data is not large. But I was looking for a simpler, built in command, something like L.remove('a', all) or L.removeall('a'). Python has re.findall function, but why not removeall, so users have to make up long lines of

Re: Delete all items in the list

2009-02-27 Thread Chris Rebert
On Fri, Feb 27, 2009 at 5:10 AM, Steve Holden wrote: > Chris Rebert wrote: >> On Thu, Feb 26, 2009 at 10:26 PM, odeits wrote: > [...] >>> while 'a' in L: >>>   L.remove('a') >>> >>> not the most efficient but it works >> >> "Not the most efficient"; it's terribly inefficient! It's 2*O(M*N) [M >>

Re: Delete all items in the list

2009-02-27 Thread Steve Holden
Chris Rebert wrote: > On Thu, Feb 26, 2009 at 10:26 PM, odeits wrote: [...] >> while 'a' in L: >> L.remove('a') >> >> not the most efficient but it works > > "Not the most efficient"; it's terribly inefficient! It's 2*O(M*N) [M > = number of 'a's in L], versus just N. And that's not even accoun

Re: Delete all items in the list

2009-02-26 Thread Chris Rebert
On Thu, Feb 26, 2009 at 10:26 PM, odeits wrote: > On Feb 26, 3:05 am, Clarendon 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

Re: Delete all items in the list

2009-02-26 Thread odeits
On Feb 26, 3:05 am, Clarendon 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') o

Re: Delete all items in the list

2009-02-26 Thread Chris Rebert
On Thu, Feb 26, 2009 at 4:37 PM, Gabriel Genellina wrote: > En Thu, 26 Feb 2009 22:18:18 -0200, Chris Rebert > escribió: >> >> On Thu, Feb 26, 2009 at 4:08 PM, Peter Billam >> wrote: >>> >>> On 2009-02-26, Clarendon wrote: Hi. This must be a simple command but I just can't find it in

Re: Delete all items in the list

2009-02-26 Thread Gabriel Genellina
En Thu, 26 Feb 2009 22:18:18 -0200, Chris Rebert escribió: On Thu, Feb 26, 2009 at 4:08 PM, Peter Billam wrote: On 2009-02-26, Clarendon 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? F

Re: Delete all items in the list

2009-02-26 Thread Steve Holden
Peter Billam wrote: > On 2009-02-26, Clarendon 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

Re: Delete all items in the list

2009-02-26 Thread Peter Billam
On 2009-02-27, Chris Rebert wrote: > On Thu, Feb 26, 2009 at 4:08 PM, Peter Billam wrote: >> On 2009-02-26, Clarendon wrote: >>> 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.

Re: Delete all items in the list

2009-02-26 Thread Gabriel Genellina
En Thu, 26 Feb 2009 22:08:26 -0200, Peter Billam escribió: On 2009-02-26, Clarendon 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

Re: Delete all items in the list

2009-02-26 Thread Chris Rebert
On Thu, Feb 26, 2009 at 4:08 PM, Peter Billam wrote: > On 2009-02-26, Clarendon 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 dele

Re: Delete all items in the list

2009-02-26 Thread Peter Billam
On 2009-02-26, Clarendon 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 de

Re: Delete all items in the list

2009-02-26 Thread Steve Holden
Terry Reedy wrote: > Steve Holden wrote: >> Terry Reedy wrote: >>> Gabriel Genellina wrote: >>> > L = filter('a'.__ne__,L) And this is probably the fastest. But not all types define __ne__ >>> In Py3, all classes inherit .__ne__ from 'object'. >>> >> Isn't that inherited method just an id

Re: Delete all items in the list

2009-02-26 Thread Terry Reedy
Steve Holden wrote: Terry Reedy wrote: Gabriel Genellina wrote: L = filter('a'.__ne__,L) And this is probably the fastest. But not all types define __ne__ In Py3, all classes inherit .__ne__ from 'object'. Isn't that inherited method just an identity comparison? Yes. And so is, by defau

Re: Delete all items in the list

2009-02-26 Thread Steve Holden
Terry Reedy wrote: > Gabriel Genellina wrote: > >> >>> L = filter('a'.__ne__,L) >> >> And this is probably the fastest. But not all types define __ne__ > > In Py3, all classes inherit .__ne__ from 'object'. > Isn't that inherited method just an identity comparison? However in this particular c

Re: Delete all items in the list

2009-02-26 Thread Terry Reedy
Gabriel Genellina wrote: L = filter('a'.__ne__,L) And this is probably the fastest. But not all types define __ne__ In Py3, all classes inherit .__ne__ from 'object'. -- http://mail.python.org/mailman/listinfo/python-list

functools.partial (was: Delete all items in the list)

2009-02-26 Thread John Posner
>> >> from functools import partial >> from operator import ne >> L = filter(partial(ne, 'a'), L) >> I learned about functools.partial only recently (on this list). functools is implemented in C, not Python, so I couldn't answer this question for myself: Is functools.partial completely

RE: Delete all items in the list

2009-02-26 Thread John Posner
>> >> > L = filter('a'.__ne__,L) >> >> And this is probably the fastest. But not all types define >> __ne__ so a >> more generic answer would be: >> >> from functools import partial >> from operator import ne >> L = filter(partial(ne, 'a'), L) >> And don't forget this "traditio

Re: Delete all items in the list

2009-02-26 Thread Gabriel Genellina
En Thu, 26 Feb 2009 11:00:30 -0200, Boris Borcic escribió: Chris Rebert wrote: On Thu, Feb 26, 2009 at 3:05 AM, Clarendon 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 s

Re: Delete all items in the list

2009-02-26 Thread Boris Borcic
Chris Rebert wrote: On Thu, Feb 26, 2009 at 3:05 AM, Clarendon 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 coupl

Re: Delete all items in the list

2009-02-26 Thread Bruno Desthuilliers
Clarendon a écrit : 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'. Ho

Re: Delete all items in the list

2009-02-26 Thread Chris Rebert
On Thu, Feb 26, 2009 at 3:05 AM, Clarendon 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.

Delete all items in the list

2009-02-26 Thread Clarendon
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