code: def sort_states(states, sort_list):
      sorted_states= states.copy()
      for sort_pair in reversed( _convert_list_of_dict_to_tuple(sort_list) ):
          if sort_pair[0].lstrip('-') in ['data','measure','meta']:
              sorted_states= _state_value_sort(sorted_states, sort_pair, _state_key_function)
          elif sort_pair[0] == 'groupings':
              for grouping in reversed(sort_pair[1]):
                  sorted_states= _groupings_values_sort(sorted_states, grouping)
      return sorted_states