def _MakeRanges(pairs):
  """Turn a list like [(65,97), (66, 98), ..., (90,122)]
     into [(65, 90, +32)]."""
  ranges = []
  last = -100

  def evenodd(last, a, b, r):
    if a != last+1 or b != _AddDelta(a, r[2]):
      return False
    r[1] = a
    return True

  def evenoddpair(last, a, b, r):
    if a != last+2:
      return False
    delta = r[2]
    d = delta
    if type(delta) is not str:
      return False
    if delta.endswith('Skip'):
      d = delta[:-4]
    else:
      delta = d + 'Skip'
    if b != _AddDelta(a, d):
      return False
    r[1] = a
    r[2] = delta
    return True

  for a, b in pairs:
    if ranges and evenodd(last, a, b, ranges[-1]):
      pass
    elif ranges and evenoddpair(last, a, b, ranges[-1]):
      pass
    else:
      ranges.append([a, a, _Delta(a, b)])
    last = a
  return ranges
def _MakeRanges ( pairs ) : ranges = [ ] last = - 100 def evenodd ( last , a , b , r ) : if a != last + 1 or b != _AddDelta ( a , r [ 2 ] ) : return False r [ 1 ] = a return True def evenoddpair ( last , a , b , r ) : if a != last + 2 : return False delta = r [ 2 ] d = delta if type ( delta ) is not str : return False if delta . endswith ( 'Skip' ) : d = delta [ : - 4 ] else : delta = d + 'Skip' if b != _AddDelta ( a , d ) : return False r [ 1 ] = a r [ 2 ] = delta return True for a , b in pairs : if ranges and evenodd ( last , a , b , ranges [ - 1 ] ) : pass elif ranges and evenoddpair ( last , a , b , ranges [ - 1 ] ) : pass else : ranges . append ( [ a , a , _Delta ( a , b ) ] ) last = a return ranges
Turn a list like [(65,97), (66, 98), ..., (90,122)]
     into [(65, 90, +32)].