A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-October/039455.html below:

[Python-Dev] PyList API missing PyList_Pop() and PyList_Delete

[Python-Dev] PyList API missing PyList_Pop() and PyList_DeleteGuido van Rossum guido at python.org
Fri Oct 24 14:24:52 EDT 2003
> I ended-up using:
> 
>  	PyObject_CallMethod(to->outbasket, "pop", NULL);
> 
> The bummer is that this call is effectively used in a loop and runs once
> for every data element in an iterable.  Something like pop() has such a
> tiny granularity that its runtime is overwhelmed by the lookup time to
> 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)]

IOW:

PyObject *
listpop(PyObject *lst)
{
    PyObject *x;
    int n;

    n = PyList_GET_SIZE(lst);
    if (n == 0)
        return NULL;
    x = PyList_GET_ITEM(lst, n-1);
    Py_INCREF(x);
    PyList_SetSlice(lst, n-1, n, NULL);
    return x;
}

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.).

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4