def slices(indices):
 indices = list(sorted(indices))
 if indices:
  first = last = indices[0]
  for i in indices[1:]:
   if (i == (last + 1)):
    last = i
   else:
    (yield (first, (last + 1)))
    first = last = i
  (yield (first, (last + 1)))

def slices ( indices ) : indices = list ( sorted ( indices ) ) if indices : first = last = indices [ 0 ] for i in indices [ 1 : ] : if ( i == ( last + 1 ) ) : last = i else : ( yield ( first , ( last + 1 ) ) ) first = last = i ( yield ( first , ( last + 1 ) ) )
group the given integer indices into slices .