Skip to content

Commit 49392c6

Browse files
authored
bpo-27385: Clarify docstring for groupby() (#3738)
1 parent 57c2561 commit 49392c6

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Doc/library/itertools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Iterator Arguments Results
5353
:func:`compress` data, selectors (d[0] if s[0]), (d[1] if s[1]), ... ``compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F``
5454
:func:`dropwhile` pred, seq seq[n], seq[n+1], starting when pred fails ``dropwhile(lambda x: x<5, [1,4,6,4,1]) --> 6 4 1``
5555
:func:`filterfalse` pred, seq elements of seq where pred(elem) is false ``filterfalse(lambda x: x%2, range(10)) --> 0 2 4 6 8``
56-
:func:`groupby` iterable[, keyfunc] sub-iterators grouped by value of keyfunc(v)
56+
:func:`groupby` iterable[, key] sub-iterators grouped by value of key(v)
5757
:func:`islice` seq, [start,] stop [, step] elements from seq[start:stop:step] ``islice('ABCDEFG', 2, None) --> C D E F G``
5858
:func:`starmap` func, seq func(\*seq[0]), func(\*seq[1]), ... ``starmap(pow, [(2,5), (3,2), (10,3)]) --> 32 9 1000``
5959
:func:`takewhile` pred, seq seq[0], seq[1], until pred fails ``takewhile(lambda x: x<5, [1,4,6,4,1]) --> 1 4``

Modules/itertoolsmodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ static PyMethodDef groupby_methods[] = {
176176
};
177177

178178
PyDoc_STRVAR(groupby_doc,
179-
"groupby(iterable[, keyfunc]) -> create an iterator which returns\n\
180-
(key, sub-iterator) grouped by each value of key(value).\n");
179+
"groupby(iterable, key=None) -> make an iterator that returns consecutive\n\
180+
keys and groups from the iterable. If the key function is not specified or\n\
181+
is None, the element itself is used for grouping.\n");
181182

182183
static PyTypeObject groupby_type = {
183184
PyVarObject_HEAD_INIT(NULL, 0)

0 commit comments

Comments
 (0)