[Tutor] a question about list

Bill Mill bill.mill at gmail.com
Fri Nov 12 15:16:21 CET 2004


> Strange, in my testing it is slower to use a.pop(i) than del a[i]; i.e.
> your remove2 above is slower than my remove1. I tried both Python 2.3.4
> and Python 2.4 on Win2k. Are you sure you read the results correctly?
> (When the function name in the results is different from the name in the
> presented code I have to wonder...)

Yup, I fail it. I'm not getting those results anymore - it was late
last night. That's my excuse and I'm sticking to it.

> > By the by, the built-in list.remove function is horribly slow for this
> > task, I found. I *guess* it's because a.remove(a[i]) has an extra list
> > access, but that doesn't explain a time of .7 secs on this test.
> > Anybody got a guess why?
> a.remove(a[i]) is removing by _value_, not by index. So it has to search
> the list for the value to be removed. This is very slow compared to del
> a[i] which goes right to the correct spot in the list.

Seems to make sense.

Bill Mill
bill.mill at gmail.com

More information about the Tutor mailing list