On Dec 28, 4:56 am, patrick.wa... at gmail.com wrote: > from itertools import groupby You seem to have overlooked this important sentence in the documentation: "Generally, the iterable needs to already be sorted on the same key function"