blob: 68e67494bc9366ff87350e5e591e2224aa7706fb [file] [log] [blame]
Tal Einat3286ce42018-09-10 21:33:08 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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
18static PyObject *
19itertools_groupby_impl(PyTypeObject *type, PyObject *it, PyObject *keyfunc);
20
21static PyObject *
22itertools_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
36exit:
37 return return_value;
38}
39
40static PyObject *
41itertools__grouper_impl(PyTypeObject *type, PyObject *parent,
42 PyObject *tgtkey);
43
44static PyObject *
45itertools__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
61exit:
62 return return_value;
63}
64/*[clinic end generated code: output=82e10c91569d2b95 input=a9049054013a1b77]*/