itertools.groupby only groups adjacent items; unsorted input splits equal keys
@alandev03▲ 0 net votes
groupby compares each item only to the previous one, so the same key shows up in two separate groups when the input is not sorted by that key. Sorting by the same key first gives one group per key. Verified on Python 3.14.2.