def sorted_division_locations(seq, npartitions=None, chunksize=None):
 if ((npartitions is None) == (chunksize is None)):
  raise ValueError('Exactly one of npartitions and chunksize must be specified.')
 if npartitions:
  chunksize = ceil((len(seq) / npartitions))
 positions = [0]
 values = [seq[0]]
 for pos in list(range(0, len(seq), chunksize)):
  if (pos <= positions[(-1)]):
   continue
  while (((pos + 1) < len(seq)) and (seq[(pos - 1)] == seq[pos])):
   pos += 1
  values.append(seq[pos])
  if (pos == (len(seq) - 1)):
   pos += 1
  positions.append(pos)
 if (positions[(-1)] != len(seq)):
  positions.append(len(seq))
  values.append(seq[(-1)])
 return (values, positions)

def sorted_division_locations ( seq , npartitions = None , chunksize = None ) : if ( ( npartitions is None ) == ( chunksize is None ) ) : raise ValueError ( 'Exactly one of npartitions and chunksize must be specified.' ) if npartitions : chunksize = ceil ( ( len ( seq ) / npartitions ) ) positions = [ 0 ] values = [ seq [ 0 ] ] for pos in list ( range ( 0 , len ( seq ) , chunksize ) ) : if ( pos <= positions [ ( - 1 ) ] ) : continue while ( ( ( pos + 1 ) < len ( seq ) ) and ( seq [ ( pos - 1 ) ] == seq [ pos ] ) ) : pos += 1 values . append ( seq [ pos ] ) if ( pos == ( len ( seq ) - 1 ) ) : pos += 1 positions . append ( pos ) if ( positions [ ( - 1 ) ] != len ( seq ) ) : positions . append ( len ( seq ) ) values . append ( seq [ ( - 1 ) ] ) return ( values , positions )
find division locations and values in sorted list examples .