code: def sort_dict(dict_, part='keys', key=None, reverse=False):
      if part == 'keys':
          index = 0
      elif part in {'vals', 'values'}:
          index = 1
      else:
          raise ValueError('Unknown method part=%r' % (part,))
      if key is None:
          _key = op.itemgetter(index)
      else:
          def _key(item):
              return key(item[index])
      sorted_items = sorted(six.iteritems(dict_), key=_key, reverse=reverse)
      sorted_dict = OrderedDict(sorted_items)
      return sorted_dict