nodes: 0, module; 1, function_definition; 2, function_name:solve_sort; 3, parameters; 4, block; 5, identifier:expr; 6, identifier:vars; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, function_definition; 11, expression_statement; 12, return_statement; 13, comment:"""Sort values on the LHS by the value they yield when passed to RHS."""; 14, assignment; 15, assignment; 16, function_name:_key_func; 17, parameters; 18, block; 19, assignment; 20, call; 21, identifier:lhs_values; 22, call; 23, identifier:sort_expression; 24, attribute; 25, identifier:x; 26, return_statement; 27, identifier:results; 28, call; 29, identifier:Result; 30, argument_list; 31, attribute; 32, argument_list; 33, identifier:expr; 34, identifier:rhs; 35, attribute; 36, attribute; 37, argument_list; 38, call; 39, tuple; 40, identifier:repeated; 41, identifier:getvalues; 42, subscript; 43, call; 44, identifier:value; 45, identifier:ordered; 46, identifier:ordered; 47, identifier:lhs_values; 48, keyword_argument; 49, attribute; 50, argument_list; 51, call; 52, integer:0; 53, identifier:solve; 54, argument_list; 55, identifier:key_func; 56, identifier:_key_func; 57, identifier:repeated; 58, identifier:meld; 59, list_splat; 60, identifier:__solve_for_repeated; 61, argument_list; 62, identifier:sort_expression; 63, call; 64, identifier:results; 65, attribute; 66, identifier:vars; 67, identifier:__nest_scope; 68, argument_list; 69, identifier:expr; 70, identifier:lhs; 71, attribute; 72, identifier:vars; 73, identifier:x; 74, identifier:expr; 75, identifier:lhs
code: def solve_sort(expr, vars):
      """Sort values on the LHS by the value they yield when passed to RHS."""
      lhs_values = repeated.getvalues(__solve_for_repeated(expr.lhs, vars)[0])
  
      sort_expression = expr.rhs
  
      def _key_func(x):
          return solve(sort_expression, __nest_scope(expr.lhs, vars, x)).value
  
      results = ordered.ordered(lhs_values, key_func=_key_func)
  
      return Result(repeated.meld(*results), ())