code: def get_sort_function(order):
      
      stable = tuple((d['key'], -1 if d['reverse'] else 1) for d in order)
      def sort_function(a, b):
          for name, direction in stable:
              v = cmp(getattr(a, name) if a else a, getattr(b, name) if b else b)
              if v != 0:
                  return v * direction
          return 0
      return sort_function
docs: Returns a callable similar to the built-in `cmp`, to be used on objects.
  
      Takes a list of dictionaries. In each, 'key' must be a string that is
      used to get an attribute of the objects to compare, and 'reverse' must
      be a boolean indicating whether the result should be reversed.