diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c index 7455fbc9162..8fe742ff0eb 100644 --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -216,6 +216,80 @@ heapify(PyObject *self, PyObject *heap) PyDoc_STRVAR(heapify_doc, "Transform list into a heap, in-place, in O(len(heap)) time."); +static PyObject * +nlargest(PyObject *self, PyObject *args) +{ + PyObject *heap=NULL, *elem, *rv, *iterable, *sol, *it, *oldelem; + int i, n; + + if (!PyArg_ParseTuple(args, "Oi:nlargest", &iterable, &n)) + return NULL; + + it = PyObject_GetIter(iterable); + if (it == NULL) + return NULL; + + heap = PyList_New(0); + if (it == NULL) + goto fail; + + for (i=0 ; i