def conforms_partial_ordering(tuples, sorted_elements):
 deps = defaultdict(set)
 for (parent, child) in tuples:
  deps[parent].add(child)
 for (i, node) in enumerate(sorted_elements):
  for n in sorted_elements[i:]:
   if (node in deps[n]):
    return False
 else:
  return True

def conforms_partial_ordering ( tuples , sorted_elements ) : deps = defaultdict ( set ) for ( parent , child ) in tuples : deps [ parent ] . add ( child ) for ( i , node ) in enumerate ( sorted_elements ) : for n in sorted_elements [ i : ] : if ( node in deps [ n ] ) : return False else : return True
true if the given sorting conforms to the given partial ordering .