So ``a`` is already sorted? Use groupby? Cheers, Alan Isaac >>> from itertools import groupby >>> for t,v in groupby(a): print list(v) ... [2] [3] [4, 4, 4, 4] [5] [6, 6] [8, 8, 8] [10, 10]