Tal Einat | 3286ce4 | 2018-09-10 21:33:08 +0300 | [diff] [blame^] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(itertools_groupby__doc__, |
| 6 | "groupby(iterable, key=None)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "make an iterator that returns consecutive keys and groups from the iterable\n" |
| 10 | "\n" |
| 11 | " iterable\n" |
| 12 | " Elements to divide into groups according to the key function.\n" |
| 13 | " key\n" |
| 14 | " A function for computing the group category for each element.\n" |
| 15 | " If the key function is not specified or is None, the element itself\n" |
| 16 | " is used for grouping."); |
| 17 | |
| 18 | static PyObject * |
| 19 | itertools_groupby_impl(PyTypeObject *type, PyObject *it, PyObject *keyfunc); |
| 20 | |
| 21 | static PyObject * |
| 22 | itertools_groupby(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 23 | { |
| 24 | PyObject *return_value = NULL; |
| 25 | static const char * const _keywords[] = {"iterable", "key", NULL}; |
| 26 | static _PyArg_Parser _parser = {"O|O:groupby", _keywords, 0}; |
| 27 | PyObject *it; |
| 28 | PyObject *keyfunc = Py_None; |
| 29 | |
| 30 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
| 31 | &it, &keyfunc)) { |
| 32 | goto exit; |
| 33 | } |
| 34 | return_value = itertools_groupby_impl(type, it, keyfunc); |
| 35 | |
| 36 | exit: |
| 37 | return return_value; |
| 38 | } |
| 39 | |
| 40 | static PyObject * |
| 41 | itertools__grouper_impl(PyTypeObject *type, PyObject *parent, |
| 42 | PyObject *tgtkey); |
| 43 | |
| 44 | static PyObject * |
| 45 | itertools__grouper(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 46 | { |
| 47 | PyObject *return_value = NULL; |
| 48 | PyObject *parent; |
| 49 | PyObject *tgtkey; |
| 50 | |
| 51 | if ((type == &_grouper_type) && |
| 52 | !_PyArg_NoKeywords("_grouper", kwargs)) { |
| 53 | goto exit; |
| 54 | } |
| 55 | if (!PyArg_ParseTuple(args, "O!O:_grouper", |
| 56 | &groupby_type, &parent, &tgtkey)) { |
| 57 | goto exit; |
| 58 | } |
| 59 | return_value = itertools__grouper_impl(type, parent, tgtkey); |
| 60 | |
| 61 | exit: |
| 62 | return return_value; |
| 63 | } |
| 64 | /*[clinic end generated code: output=82e10c91569d2b95 input=a9049054013a1b77]*/ |