def mergeOrderings(orderings, seen=None):
 if (seen is None):
  seen = {}
 result = []
 orderings.reverse()
 for ordering in orderings:
  ordering = list(ordering)
  ordering.reverse()
  for o in ordering:
   if (o not in seen):
    seen[o] = 1
    result.append(o)
 result.reverse()
 return result

def mergeOrderings ( orderings , seen = None ) : if ( seen is None ) : seen = { } result = [ ] orderings . reverse ( ) for ordering in orderings : ordering = list ( ordering ) ordering . reverse ( ) for o in ordering : if ( o not in seen ) : seen [ o ] = 1 result . append ( o ) result . reverse ( ) return result
merge multiple orderings so that within-ordering order is preserved orderings are constrained in such a way that if an object appears in two or more orderings .