diff options
author | Eli Bendersky <eliben@gmail.com> | 2011-02-25 05:47:53 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2011-02-25 05:47:53 (GMT) |
commit | cbbaa96036b8467c21f2c7127a3711fcb405d00f (patch) | |
tree | eb49c673b4b8adb17eb3bf17188c65df9d5f89ea /Objects/listobject.c | |
parent | 3108f983197991865c30d49de37b9a48e60c656e (diff) | |
download | cpython-cbbaa96036b8467c21f2c7127a3711fcb405d00f.zip cpython-cbbaa96036b8467c21f2c7127a3711fcb405d00f.tar.gz cpython-cbbaa96036b8467c21f2c7127a3711fcb405d00f.tar.bz2 |
Issue #10516: adding list.clear() and list.copy() methods
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 2e0c8aa..9b2d36f 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -747,6 +747,19 @@ listinsert(PyListObject *self, PyObject *args) } static PyObject * +listclear(PyListObject *self) +{ + list_clear(self); + Py_RETURN_NONE; +} + +static PyObject * +listcopy(PyListObject *self) +{ + return list_slice(self, 0, Py_SIZE(self)); +} + +static PyObject * listappend(PyListObject *self, PyObject *v) { if (app1(self, v) == 0) @@ -2322,6 +2335,10 @@ PyDoc_STRVAR(reversed_doc, "L.__reversed__() -- return a reverse iterator over the list"); PyDoc_STRVAR(sizeof_doc, "L.__sizeof__() -- size of L in memory, in bytes"); +PyDoc_STRVAR(clear_doc, +"L.clear() -> None -- remove all items from L"); +PyDoc_STRVAR(copy_doc, +"L.copy() -> list -- a shallow copy of L"); PyDoc_STRVAR(append_doc, "L.append(object) -- append object to end"); PyDoc_STRVAR(extend_doc, @@ -2350,9 +2367,11 @@ static PyMethodDef list_methods[] = { {"__getitem__", (PyCFunction)list_subscript, METH_O|METH_COEXIST, getitem_doc}, {"__reversed__",(PyCFunction)list_reversed, METH_NOARGS, reversed_doc}, {"__sizeof__", (PyCFunction)list_sizeof, METH_NOARGS, sizeof_doc}, + {"clear", (PyCFunction)listclear, METH_NOARGS, clear_doc}, + {"copy", (PyCFunction)listcopy, METH_NOARGS, copy_doc}, {"append", (PyCFunction)listappend, METH_O, append_doc}, {"insert", (PyCFunction)listinsert, METH_VARARGS, insert_doc}, - {"extend", (PyCFunction)listextend, METH_O, extend_doc}, + {"extend", (PyCFunction)listextend, METH_O, extend_doc}, {"pop", (PyCFunction)listpop, METH_VARARGS, pop_doc}, {"remove", (PyCFunction)listremove, METH_O, remove_doc}, {"index", (PyCFunction)listindex, METH_VARARGS, index_doc}, |