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