[Python-Dev] PyList API missing PyList_Pop() and PyList_Delete
python at rcn.com
Fri Oct 24 15:01:09 EDT 2003
> -----Original Message-----
> > The bummer is that this call is effectively used in a loop and runs
> > for every data element in an iterable. Something like pop() has
> > tiny granularity that its runtime is overwhelmed by the lookup time
> > call it this way. For this reason, I think PyList_Pop() warrants
> > inclusion in the API much more than low granularity methods like
> > PyList_Reverse() or PyList_Sort().
> But it's easy to simulate a pop, writing the C equivalent of
> x = lst[len(lst)-1]
> del lst[len(lst)-1 : len(lst)]
. . .
> PyList_SetSlice(lst, n-1, n, NULL);
There's the new piece of information. I didn't know that the final
argument could be NULL and creating/destroying and empty list for the
arg was unpleasant. I'll add that info to the API docs.
> I see no need to add this to the public API just yet (it would have to
> be more flexible to allow lst.pop(n), do more arg checks, etc.).
Yes. See if more requestors come along.
Surely, I was not the first to want to use PyLists as append/pop stacks
More information about the Python-Dev