Partitioning an iterator with groupby()