This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: the iterable for itertools.groupby must be sorted
Type: Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: cheryl.sabella, docs@python, matrixise
Priority: normal Keywords: patch

Created on 2018-01-29 12:40 by matrixise, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 5424 closed matrixise, 2018-01-29 12:42
Messages (4)
msg311115 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-01-29 12:40
The documentation of itertools.groupby indicates that generally, the iterable needs to be sorted. In fact, this iterable MUST be sorted.
msg311119 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-01-29 12:49
It depends upon your use case.

In general, if you want it to work like SQL group by, then yes, it needs to be sorted, and I believe the documentation already covers that.  However, there are scenarios where you want to condense a string, but keep the ordering, such as:

'aaaaabbbbbbccccaaaaddd' into '5a6b4c4a3d'

and itertools.groupby works very nicely for that.
msg311120 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-01-29 12:53
good catch, I only use itertools.groupby when I work for a collection.
msg311121 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-01-29 12:54
I am going to close my issue because with your use case, this issue makes no sense.
History
Date User Action Args
2022-04-11 14:58:57adminsetgithub: 76890
2018-01-29 12:54:45matrixisesetstatus: open -> closed

messages: + msg311121
stage: patch review -> resolved
2018-01-29 12:53:37matrixisesetmessages: + msg311120
2018-01-29 12:49:59cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg311119
2018-01-29 12:42:54matrixisesetkeywords: + patch
stage: patch review
pull_requests: + pull_request5259
2018-01-29 12:40:46matrixisecreate