nodes: 0, module; 1, function_definition; 2, function_name:index_list_for_sort_order; 3, parameters; 4, type; 5, block; 6, typed_parameter; 7, typed_default_parameter; 8, typed_default_parameter; 9, generic_type; 10, expression_statement; 11, function_definition; 12, if_statement; 13, expression_statement; 14, return_statement; 15, identifier:x; 16, type; 17, identifier:key; 18, type; 19, None; 20, identifier:reverse; 21, type; 22, False; 23, identifier:List; 24, type_parameter; 25, comment:"""
      Returns a list of indexes of ``x``, IF ``x`` WERE TO BE SORTED.
  
      Args:
          x: data
          key: function to be applied to the data to generate a sort key; this
              function is passed as the ``key=`` parameter to :func:`sorted`;
              the default is ``itemgetter(1)``
          reverse: reverse the sort order?
  
      Returns:
          list of integer index values
  
      Example:
  
      .. code-block:: python
  
          z = ["a", "c", "b"]
          index_list_for_sort_order(z)  # [0, 2, 1]
          index_list_for_sort_order(z, reverse=True)  # [1, 2, 0]
          q = [("a", 9), ("b", 8), ("c", 7)]
          index_list_for_sort_order(q, key=itemgetter(1))
  
      """; 26, function_name:key_with_user_func; 27, parameters; 28, block; 29, identifier:key; 30, block; 31, else_clause; 32, assignment; 33, list_comprehension; 34, generic_type; 35, generic_type; 36, identifier:bool; 37, type; 38, typed_parameter; 39, return_statement; 40, expression_statement; 41, comment:# see the simpler version below; 42, block; 43, identifier:index_value_list; 44, call; 45, identifier:i; 46, for_in_clause; 47, identifier:List; 48, type_parameter; 49, identifier:Callable; 50, type_parameter; 51, identifier:int; 52, identifier:idx_val; 53, type; 54, call; 55, assignment; 56, expression_statement; 57, comment:# enumerate, below, will return tuples of (index, value), so; 58, comment:# itemgetter(1) means sort by the value; 59, identifier:sorted; 60, argument_list; 61, pattern_list; 62, identifier:index_value_list; 63, type; 64, type; 65, type; 66, generic_type; 67, identifier:key; 68, argument_list; 69, identifier:sort_key; 70, identifier:key_with_user_func; 71, assignment; 72, call; 73, keyword_argument; 74, keyword_argument; 75, identifier:i; 76, identifier:_; 77, identifier:Any; 78, list; 79, identifier:Any; 80, identifier:Tuple; 81, type_parameter; 82, subscript; 83, identifier:sort_key; 84, call; 85, identifier:enumerate; 86, argument_list; 87, identifier:key; 88, identifier:sort_key; 89, identifier:reverse; 90, identifier:reverse; 91, identifier:Any; 92, type; 93, type; 94, identifier:idx_val; 95, integer:1; 96, identifier:itemgetter; 97, argument_list; 98, identifier:x; 99, identifier:int; 100, identifier:Any; 101, integer:1
code: def index_list_for_sort_order(x: List[Any], key: Callable[[Any], Any] = None,
                                reverse: bool = False) -> List[int]:
      """
      Returns a list of indexes of ``x``, IF ``x`` WERE TO BE SORTED.
  
      Args:
          x: data
          key: function to be applied to the data to generate a sort key; this
              function is passed as the ``key=`` parameter to :func:`sorted`;
              the default is ``itemgetter(1)``
          reverse: reverse the sort order?
  
      Returns:
          list of integer index values
  
      Example:
  
      .. code-block:: python
  
          z = ["a", "c", "b"]
          index_list_for_sort_order(z)  # [0, 2, 1]
          index_list_for_sort_order(z, reverse=True)  # [1, 2, 0]
          q = [("a", 9), ("b", 8), ("c", 7)]
          index_list_for_sort_order(q, key=itemgetter(1))
  
      """
      def key_with_user_func(idx_val: Tuple[int, Any]):
          return key(idx_val[1])
      if key:
          sort_key = key_with_user_func
          # see the simpler version below
      else:
          sort_key = itemgetter(1)
          # enumerate, below, will return tuples of (index, value), so
          # itemgetter(1) means sort by the value
      index_value_list = sorted(enumerate(x), key=sort_key, reverse=reverse)
      return [i for i, _ in index_value_list]