nodes: 0, module; 1, function_definition; 2, function_name:sortTitles; 3, parameters; 4, block; 5, identifier:self; 6, identifier:by; 7, expression_statement; 8, comment:# First sort titles by the secondary key, which is always the title.; 9, expression_statement; 10, comment:# Then sort on the primary key (if any).; 11, if_statement; 12, if_statement; 13, if_statement; 14, if_statement; 15, if_statement; 16, raise_statement; 17, comment:"""
          Sort titles by a given attribute and then by title.
  
          @param by: A C{str}, one of 'length', 'maxScore', 'medianScore',
              'readCount', or 'title'.
          @raise ValueError: If an unknown C{by} value is given.
          @return: A sorted C{list} of titles.
          """; 18, assignment; 19, comparison_operator:by == 'length'; 20, block; 21, comparison_operator:by == 'maxScore'; 22, block; 23, comparison_operator:by == 'medianScore'; 24, block; 25, comparison_operator:by == 'readCount'; 26, block; 27, comparison_operator:by == 'title'; 28, block; 29, call; 30, identifier:titles; 31, call; 32, identifier:by; 33, string; 34, return_statement; 35, identifier:by; 36, string; 37, return_statement; 38, identifier:by; 39, string; 40, return_statement; 41, identifier:by; 42, string; 43, return_statement; 44, identifier:by; 45, string; 46, return_statement; 47, identifier:ValueError; 48, argument_list; 49, identifier:sorted; 50, argument_list; 51, string_content:length; 52, call; 53, string_content:maxScore; 54, call; 55, string_content:medianScore; 56, call; 57, string_content:readCount; 58, call; 59, string_content:title; 60, identifier:titles; 61, concatenated_string; 62, call; 63, identifier:sorted; 64, argument_list; 65, identifier:sorted; 66, argument_list; 67, identifier:sorted; 68, argument_list; 69, identifier:sorted; 70, argument_list; 71, string:'Sort attribute must be one of "length", "maxScore", '; 72, string:'"medianScore", "readCount", "title".'; 73, identifier:iter; 74, argument_list; 75, identifier:titles; 76, keyword_argument; 77, keyword_argument; 78, identifier:titles; 79, keyword_argument; 80, keyword_argument; 81, identifier:titles; 82, keyword_argument; 83, keyword_argument; 84, identifier:titles; 85, keyword_argument; 86, keyword_argument; 87, identifier:self; 88, identifier:reverse; 89, True; 90, identifier:key; 91, lambda; 92, identifier:reverse; 93, True; 94, identifier:key; 95, lambda; 96, identifier:reverse; 97, True; 98, identifier:key; 99, lambda; 100, identifier:reverse; 101, True; 102, identifier:key; 103, lambda; 104, lambda_parameters; 105, attribute; 106, lambda_parameters; 107, call; 108, lambda_parameters; 109, call; 110, lambda_parameters; 111, call; 112, identifier:title; 113, subscript; 114, identifier:subjectLength; 115, identifier:title; 116, attribute; 117, argument_list; 118, identifier:title; 119, attribute; 120, argument_list; 121, identifier:title; 122, attribute; 123, argument_list; 124, identifier:self; 125, identifier:title; 126, subscript; 127, identifier:bestHsp; 128, identifier:self; 129, identifier:scoreClass; 130, call; 131, subscript; 132, identifier:readCount; 133, identifier:self; 134, identifier:title; 135, attribute; 136, argument_list; 137, identifier:self; 138, identifier:title; 139, subscript; 140, identifier:medianScore; 141, identifier:self; 142, identifier:title
code: def sortTitles(self, by):
          """
          Sort titles by a given attribute and then by title.
  
          @param by: A C{str}, one of 'length', 'maxScore', 'medianScore',
              'readCount', or 'title'.
          @raise ValueError: If an unknown C{by} value is given.
          @return: A sorted C{list} of titles.
          """
          # First sort titles by the secondary key, which is always the title.
          titles = sorted(iter(self))
  
          # Then sort on the primary key (if any).
          if by == 'length':
              return sorted(
                  titles, reverse=True,
                  key=lambda title: self[title].subjectLength)
          if by == 'maxScore':
              return sorted(
                  titles, reverse=True, key=lambda title: self[title].bestHsp())
          if by == 'medianScore':
              return sorted(
                  titles, reverse=True,
                  key=lambda title: self.scoreClass(self[title].medianScore()))
          if by == 'readCount':
              return sorted(
                  titles, reverse=True,
                  key=lambda title: self[title].readCount())
          if by == 'title':
              return titles
  
          raise ValueError('Sort attribute must be one of "length", "maxScore", '
                           '"medianScore", "readCount", "title".')