code: def expr_order_key(expr):
      
      if hasattr(expr, '_order_key'):
          return expr._order_key
      try:
          if isinstance(expr.kwargs, OrderedDict):
              key_vals = expr.kwargs.values()
          else:
              key_vals = [expr.kwargs[key] for key in sorted(expr.kwargs)]
          return KeyTuple((expr.__class__.__name__, ) +
                          tuple(map(expr_order_key, expr.args)) +
                          tuple(map(expr_order_key, key_vals)))
      except AttributeError:
          return str(expr)
docs: A default order key for arbitrary expressions