nodes: 0, module; 1, function_definition; 2, function_name:argsort2; 3, parameters; 4, block; 5, identifier:indexable; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, comment:# Create an iterator of value/key pairs; 10, if_statement; 11, comment:# Sort by values and extract the keys; 12, if_statement; 13, return_statement; 14, identifier:key; 15, None; 16, identifier:reverse; 17, False; 18, comment:"""
      Returns the indices that would sort a indexable object.
  
      This is similar to np.argsort, but it is written in pure python and works
      on both lists and dictionaries.
  
      Args:
          indexable (list or dict): indexable to sort by
  
      Returns:
          list: indices: list of indices such that sorts the indexable
  
      Example:
          >>> # DISABLE_DOCTEST
          >>> import utool as ut
          >>> # argsort works on dicts
          >>> dict_ = indexable = {'a': 3, 'b': 2, 'c': 100}
          >>> indices = ut.argsort2(indexable)
          >>> assert list(ut.take(dict_, indices)) == sorted(dict_.values())
          >>> # argsort works on lists
          >>> indexable = [100, 2, 432, 10]
          >>> indices = ut.argsort2(indexable)
          >>> assert list(ut.take(indexable, indices)) == sorted(indexable)
          >>> # argsort works on iterators
          >>> indexable = reversed(range(100))
          >>> indices = ut.argsort2(indexable)
          >>> assert indices[0] == 99
      """; 19, call; 20, block; 21, else_clause; 22, comparison_operator:key is None; 23, block; 24, else_clause; 25, identifier:indices; 26, identifier:isinstance; 27, argument_list; 28, expression_statement; 29, block; 30, identifier:key; 31, None; 32, expression_statement; 33, block; 34, identifier:indexable; 35, identifier:dict; 36, assignment; 37, expression_statement; 38, assignment; 39, expression_statement; 40, identifier:vk_iter; 41, generator_expression; 42, assignment; 43, identifier:indices; 44, list_comprehension; 45, assignment; 46, tuple; 47, for_in_clause; 48, identifier:vk_iter; 49, generator_expression; 50, identifier:k; 51, for_in_clause; 52, identifier:indices; 53, list_comprehension; 54, identifier:v; 55, identifier:k; 56, pattern_list; 57, call; 58, tuple; 59, for_in_clause; 60, pattern_list; 61, call; 62, identifier:k; 63, for_in_clause; 64, identifier:k; 65, identifier:v; 66, attribute; 67, argument_list; 68, identifier:v; 69, identifier:k; 70, pattern_list; 71, call; 72, identifier:v; 73, identifier:k; 74, identifier:sorted; 75, argument_list; 76, pattern_list; 77, call; 78, identifier:indexable; 79, identifier:items; 80, identifier:k; 81, identifier:v; 82, identifier:enumerate; 83, argument_list; 84, identifier:vk_iter; 85, keyword_argument; 86, identifier:v; 87, identifier:k; 88, identifier:sorted; 89, argument_list; 90, identifier:indexable; 91, identifier:reverse; 92, identifier:reverse; 93, identifier:vk_iter; 94, keyword_argument; 95, keyword_argument; 96, identifier:key; 97, lambda; 98, identifier:reverse; 99, identifier:reverse; 100, lambda_parameters; 101, call; 102, identifier:vk; 103, identifier:key; 104, argument_list; 105, subscript; 106, identifier:vk; 107, integer:0
code: def argsort2(indexable, key=None, reverse=False):
      """
      Returns the indices that would sort a indexable object.
  
      This is similar to np.argsort, but it is written in pure python and works
      on both lists and dictionaries.
  
      Args:
          indexable (list or dict): indexable to sort by
  
      Returns:
          list: indices: list of indices such that sorts the indexable
  
      Example:
          >>> # DISABLE_DOCTEST
          >>> import utool as ut
          >>> # argsort works on dicts
          >>> dict_ = indexable = {'a': 3, 'b': 2, 'c': 100}
          >>> indices = ut.argsort2(indexable)
          >>> assert list(ut.take(dict_, indices)) == sorted(dict_.values())
          >>> # argsort works on lists
          >>> indexable = [100, 2, 432, 10]
          >>> indices = ut.argsort2(indexable)
          >>> assert list(ut.take(indexable, indices)) == sorted(indexable)
          >>> # argsort works on iterators
          >>> indexable = reversed(range(100))
          >>> indices = ut.argsort2(indexable)
          >>> assert indices[0] == 99
      """
      # Create an iterator of value/key pairs
      if isinstance(indexable, dict):
          vk_iter = ((v, k) for k, v in indexable.items())
      else:
          vk_iter = ((v, k) for k, v in enumerate(indexable))
      # Sort by values and extract the keys
      if key is None:
          indices = [k for v, k in sorted(vk_iter, reverse=reverse)]
      else:
          indices = [k for v, k in sorted(vk_iter, key=lambda vk: key(vk[0]),
                                          reverse=reverse)]
      return indices