def runs(seq, op=gt):
 cycles = []
 seq = iter(seq)
 try:
  run = [next(seq)]
 except StopIteration:
  return []
 while True:
  try:
   ei = next(seq)
  except StopIteration:
   break
  if op(ei, run[(-1)]):
   run.append(ei)
   continue
  else:
   cycles.append(run)
   run = [ei]
 if run:
  cycles.append(run)
 return cycles

def runs ( seq , op = gt ) : cycles = [ ] seq = iter ( seq ) try : run = [ next ( seq ) ] except StopIteration : return [ ] while True : try : ei = next ( seq ) except StopIteration : break if op ( ei , run [ ( - 1 ) ] ) : run . append ( ei ) continue else : cycles . append ( run ) run = [ ei ] if run : cycles . append ( run ) return cycles
group the sequence into lists in which successive elements all compare the same with the comparison operator .