nodes: 0, module; 1, function_definition; 2, function_name:_rank_results; 3, parameters; 4, type; 5, block; 6, typed_parameter; 7, typed_parameter; 8, generic_type; 9, expression_statement; 10, comment:# https://stackoverflow.com/a/73050; 11, expression_statement; 12, if_statement; 13, return_statement; 14, identifier:results; 15, type; 16, identifier:method; 17, type; 18, identifier:List; 19, type_parameter; 20, comment:"""
          Ranks results - for phenodigm results are ranks but ties need to accounted for
                          for other methods, results need to be reranked
  
          :param results: Results from search_by_attribute_set()['results'] or
                                       compare_attribute_sets()['results']
          :param method: sim method used to rank results
          :return: Sorted results list
          """; 21, assignment; 22, comparison_operator:len(sorted_results) > 0; 23, block; 24, identifier:sorted_results; 25, generic_type; 26, identifier:SimAlgorithm; 27, type; 28, identifier:sorted_results; 29, call; 30, call; 31, integer:0; 32, expression_statement; 33, expression_statement; 34, for_statement; 35, identifier:List; 36, type_parameter; 37, identifier:Dict; 38, identifier:sorted; 39, argument_list; 40, identifier:len; 41, argument_list; 42, assignment; 43, assignment; 44, identifier:result; 45, identifier:sorted_results; 46, block; 47, type; 48, identifier:results; 49, keyword_argument; 50, keyword_argument; 51, identifier:sorted_results; 52, identifier:rank; 53, integer:1; 54, identifier:previous_score; 55, subscript; 56, if_statement; 57, expression_statement; 58, expression_statement; 59, identifier:Dict; 60, identifier:reverse; 61, True; 62, identifier:key; 63, lambda; 64, subscript; 65, subscript; 66, comparison_operator:previous_score > result[OwlSim2Api.method2key[method]]; 67, block; 68, assignment; 69, assignment; 70, lambda_parameters; 71, subscript; 72, identifier:sorted_results; 73, integer:0; 74, attribute; 75, identifier:method; 76, identifier:previous_score; 77, subscript; 78, expression_statement; 79, subscript; 80, identifier:rank; 81, identifier:previous_score; 82, subscript; 83, identifier:k; 84, identifier:k; 85, subscript; 86, identifier:OwlSim2Api; 87, identifier:method2key; 88, identifier:result; 89, subscript; 90, augmented_assignment; 91, identifier:result; 92, string; 93, identifier:result; 94, subscript; 95, attribute; 96, identifier:method; 97, attribute; 98, identifier:method; 99, identifier:rank; 100, integer:1; 101, string_content:rank; 102, attribute; 103, identifier:method; 104, identifier:OwlSim2Api; 105, identifier:method2key; 106, identifier:OwlSim2Api; 107, identifier:method2key; 108, identifier:OwlSim2Api; 109, identifier:method2key
code: def _rank_results(results: List[Dict], method: SimAlgorithm) -> List[Dict]:
          """
          Ranks results - for phenodigm results are ranks but ties need to accounted for
                          for other methods, results need to be reranked
  
          :param results: Results from search_by_attribute_set()['results'] or
                                       compare_attribute_sets()['results']
          :param method: sim method used to rank results
          :return: Sorted results list
          """
          # https://stackoverflow.com/a/73050
          sorted_results = sorted(
              results, reverse=True, key=lambda k: k[OwlSim2Api.method2key[method]]
          )
          if len(sorted_results) > 0:
              rank = 1
              previous_score = sorted_results[0][OwlSim2Api.method2key[method]]
              for result in sorted_results:
                  if previous_score > result[OwlSim2Api.method2key[method]]:
                      rank += 1
                  result['rank'] = rank
                  previous_score = result[OwlSim2Api.method2key[method]]
  
          return sorted_results