code: def sorted_options(sort_options):
      return [
          {
              'title': v['title'],
              'value': ('-{0}'.format(k)
                        if v.get('default_order', 'asc') == 'desc' else k),
          }
          for k, v in
          sorted(sort_options.items(), key=lambda x: x[1].get('order', 0))
      ]