The REALLY bad thing about Python lists ..

rturpin at my-deja.com rturpin at my-deja.com
Sun May 14 14:35:47 EDT 2000


rturpin at my-deja.com writes:
>> .. Creating vectors of length n by prepending
>> elements one at a time is now an n^2 operation!
>
In article <m33dnlowv4.fsf at atrus.jesus.cam.ac.uk>,
  Michael Hudson <mwh21 at cam.ac.uk> wrote:
> So create it by appending n elements and then
> reverse it..

Of course.  Unless you have an application that
manipulates both ends of the array!

> .. this is still n^2, I guess, ..

You guess wrong.  Creating an array by appending
at the end is linear in the length of the array.

Russell


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list