Understanding Python's groupby itertool