Delete all items in the list

Steve Holden steve at holdenweb.com
Fri Feb 27 14:10:30 CET 2009


Chris Rebert wrote:
> On Thu, Feb 26, 2009 at 10:26 PM, odeits <odeits at gmail.com> 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 accounting
> for all the extra element movement done by .remove()
> 
Surely 2*O(M*N) is O(M*N) since constant factors are irrelevant in
assessing performance order?

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list