Iteration index

D-Man dsh8290 at rit.edu
Fri Jun 1 16:18:43 EDT 2001


On Fri, Jun 01, 2001 at 03:42:50PM -0400, Tim Peters wrote:
| [D-Man]
| > ...
| > It is probably O(n) because it is a linked structure and indexing
| > isn't a computed offset (like C arrays)
| 
| Python lists are contiguous vectors, same as C arrays in that respect.
| 
| see-listobject.c-ly y'rs  - tim

What is the difference between a "vector" and an "array" in this
context?  (Not as in   void[] or void*  vs.  std::vector< void* > )

I took a look at listobject.c and liistobject.h and I see that the
list itself is just a PyObject** -- a pointer to a C array on the
heap.  I also noticed in the 'ins1' function that inserting an element
(not at the end) causes all others elements to be moved.  Isn't this
pretty inefficient or is it such an infrequent operation that it
matters less than the O(1) PyList_GetItem? 

Thanks,
-D





More information about the Python-list mailing list