#NEWLINE# def mergeOrderings( orderings , seen = None ) : #NEWLINE# #INDENT# "Merge multiple orderings so that within-ordering order is preserved\n\n    Orderings are constrained in such a way that if an object appears\n    in two or more orderings, then the suffix that begins with the\n    object must be in both orderings.\n\n    For example:\n\n    >>> _mergeOrderings([\n    ... ['x', 'y', 'z'],\n    ... ['q', 'z'],\n    ... [1, 3, 5],\n    ... ['z']\n    ... ])\n    ['x', 'y', 'q', 1, 3, 5, 'z']\n\n    " #NEWLINE# if ( seen is None ) : #NEWLINE# #INDENT# seen = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# result = [ ] #NEWLINE# orderings . reverse ( ) #NEWLINE# for ordering in orderings : #NEWLINE# #INDENT# ordering = list ( ordering ) #NEWLINE# ordering . reverse ( ) #NEWLINE# for o in ordering : #NEWLINE# #INDENT# if ( o not in seen ) : #NEWLINE# #INDENT# seen [ o ] = 1 #NEWLINE# result . append ( o ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# result . reverse ( ) #NEWLINE# return result