[Tutor] why is list.pop(0) slow?

Bob Gailer bgailer@alum.rpi.edu
Wed Jun 18 18:08:14 2003


--=======2D336D59=======
Content-Type: text/plain; x-avg-checked=avg-ok-1B122C2E; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 12:32 AM 6/19/2003 +0800, Wari Wahab wrote:

>I've been playing around with very large lists and found out by chance 
>that pop(0) is 8 times slower than pop(). Is it really that bad? 
>Performance improved when the list i have is reversed and used pop().

Here's my guess:
pop() removes rightmost list element by shortening the length of the list by 1.
pop(0) removes leftmost element by shifting the rest of the elements one 
place left and then shortening the length of the list by 1.
It is the shifting that is taking a lot of time.

Bob Gailer
bgailer@alum.rpi.edu
303 442 2625

--=======2D336D59=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-1B122C2E
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.488 / Virus Database: 287 - Release Date: 6/5/2003

--=======2D336D59=======--