def _c3_merge(sequences):
 result = []
 while True:
  sequences = [s for s in sequences if s]
  if (not sequences):
   return result
  for s1 in sequences:
   candidate = s1[0]
   for s2 in sequences:
    if (candidate in s2[1:]):
     candidate = None
     break
   else:
    break
  if (not candidate):
   raise RuntimeError(u'Inconsistent hierarchy')
  result.append(candidate)
  for seq in sequences:
   if (seq[0] == candidate):
    del seq[0]

def _c3_merge ( sequences ) : result = [ ] while True : sequences = [ s for s in sequences if s ] if ( not sequences ) : return result for s1 in sequences : candidate = s1 [ 0 ] for s2 in sequences : if ( candidate in s2 [ 1 : ] ) : candidate = None break else : break if ( not candidate ) : raise RuntimeError ( u'Inconsistent hierarchy' ) result . append ( candidate ) for seq in sequences : if ( seq [ 0 ] == candidate ) : del seq [ 0 ]
merges mros in *sequences* to a single mro using the c3 algorithm .