itertools.groupby assumes inputs to be grouped are consecutive