I have a strange groupby behavior. The impression is that he ignores unsorted items.
>>> from itertools import groupby >>> arr = [1,2,3,1,2,3,1,2,3] >>> groups = groupby(arr) >>> {x: list(y) for x, y in groups} {1: [1], 2: [2], 3: [3]} >>> arr.sort() >>> groups = groupby(arr) >>> {x: list(y) for x, y in groups} {1: [1, 1, 1], 2: [2, 2, 2], 3: [3, 3, 3]} Why it happens?
PS: version 3.6.0