code: def index_list_for_sort_order(x: List[Any], key: Callable[[Any], Any] = None,
                                reverse: bool = False) -> List[int]:
      def key_with_user_func(idx_val: Tuple[int, Any]):
          return key(idx_val[1])
      if key:
          sort_key = key_with_user_func
      else:
          sort_key = itemgetter(1)
      index_value_list = sorted(enumerate(x), key=sort_key, reverse=reverse)
      return [i for i, _ in index_value_list]