Timing Difference: insert vs. append & reverse
johnfkeeling at yahoo.com
Mon Aug 2 21:52:20 CEST 2004
> A list is implemented by an array of pointers to the objects it contains.
That explains it.
> If you expected insert to be faster, perhaps you thought that Python used a
> linked-list implementation. It doesn't do this,
Yes, that is how I was thinking. It is interesting to see how
functions may perform very differently from how we may initially
expect. I've also noted an approximate two time difference between
"del list[index] and list.pop(index)". I know that they do different
things (the return value from pop), however in many places my code
uses pop and ignores the return value when it would be faster to use
del. I am making changes based on these observations now.
More information about the Python-list