nodes: 0, module; 1, function_definition; 2, function_name:sorted_by; 3, parameters; 4, type; 5, block; 6, typed_parameter; 7, string; 8, expression_statement; 9, return_statement; 10, identifier:key; 11, type; 12, string_content:QubitOrder; 13, comment:"""A basis that orders qubits ascending based on a key function.
  
          Args:
              key: A function that takes a qubit and returns a key value. The
                  basis will be ordered ascending according to these key values.
  
  
          Returns:
              A basis that orders qubits ascending based on a key function.
          """; 14, call; 15, generic_type; 16, identifier:QubitOrder; 17, argument_list; 18, identifier:Callable; 19, type_parameter; 20, lambda; 21, type; 22, type; 23, lambda_parameters; 24, call; 25, list; 26, identifier:Any; 27, identifier:qubits; 28, identifier:tuple; 29, argument_list; 30, attribute; 31, call; 32, identifier:raw_types; 33, identifier:Qid; 34, identifier:sorted; 35, argument_list; 36, identifier:qubits; 37, keyword_argument; 38, identifier:key; 39, identifier:key
code: def sorted_by(key: Callable[[raw_types.Qid], Any]) -> 'QubitOrder':
          """A basis that orders qubits ascending based on a key function.
  
          Args:
              key: A function that takes a qubit and returns a key value. The
                  basis will be ordered ascending according to these key values.
  
  
          Returns:
              A basis that orders qubits ascending based on a key function.
          """
          return QubitOrder(lambda qubits: tuple(sorted(qubits, key=key)))