python/dist/src/Objects listobject.c,2.160,2.161
Update of /cvsroot/python/python/dist/src/Objects In directory sc8-pr-cvs1:/tmp/cvs-serv6236/Objects Modified Files: listobject.c Log Message: Add list.sorted() classmethod. Index: listobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v retrieving revision 2.160 retrieving revision 2.161 diff -C2 -d -r2.160 -r2.161 *** listobject.c 16 Oct 2003 17:16:30 -0000 2.160 --- listobject.c 29 Oct 2003 06:54:43 -0000 2.161 *************** *** 2002,2005 **** --- 2002,2037 ---- static PyObject * + listsorted(PyObject *cls, PyObject *args, PyObject *kwds) + { + PyObject *newlist, *v, *seq, *compare=NULL, *keyfunc=NULL, *newargs; + static char *kwlist[] = {"iterable", "cmp", "key", "reverse", 0}; + long reverse; + + if (args != NULL) { + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOi:sorted", + kwlist, &seq, &compare, &keyfunc, &reverse)) + return NULL; + } + + newlist = PyObject_CallFunctionObjArgs(cls, seq, NULL); + if (newlist == NULL) + return NULL; + + newargs = PyTuple_GetSlice(args, 1, 4); + if (newargs == NULL) { + Py_DECREF(newlist); + return NULL; + } + v = listsort((PyListObject *)newlist, newargs, kwds); + Py_DECREF(newargs); + if (v == NULL) { + Py_DECREF(newlist); + return NULL; + } + Py_DECREF(v); + return newlist; + } + + static PyObject * listreverse(PyListObject *self) { *************** *** 2336,2339 **** --- 2368,2374 ---- "L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;\n\ cmp(x, y) -> -1, 0, 1"); + PyDoc_STRVAR(sorted_doc, + "list.sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list;\n\ + cmp(x, y) -> -1, 0, 1"); static PyMethodDef list_methods[] = { *************** *** 2347,2350 **** --- 2382,2387 ---- {"reverse", (PyCFunction)listreverse, METH_NOARGS, reverse_doc}, {"sort", (PyCFunction)listsort, METH_VARARGS | METH_KEYWORDS, sort_doc}, + {"sorted", (PyCFunction)listsorted, + METH_VARARGS | METH_KEYWORDS | METH_CLASS, sorted_doc}, {NULL, NULL} /* sentinel */ };
participants (1)
-
rhettingerīŧ users.sourceforge.net