nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, comment:# Sort triggers by word and character length first; 8, for_statement; 9, comment:# Finally, sort triggers by priority; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, comment:"""
          Sort triggers and their associated responses
          """; 14, pattern_list; 15, call; 16, block; 17, assignment; 18, identifier:triggers; 19, list_comprehension; 20, block; 21, assignment; 22, identifier:priority; 23, identifier:triggers; 24, attribute; 25, argument_list; 26, expression_statement; 27, comment:# Get and sort our atomic and wildcard patterns; 28, expression_statement; 29, expression_statement; 30, expression_statement; 31, expression_statement; 32, comment:# Replace our sorted triggers; 33, expression_statement; 34, attribute; 35, list; 36, subscript; 37, for_in_clause; 38, for_statement; 39, attribute; 40, True; 41, attribute; 42, identifier:items; 43, call; 44, assignment; 45, assignment; 46, assignment; 47, assignment; 48, assignment; 49, identifier:self; 50, identifier:_sorted_triggers; 51, attribute; 52, identifier:priority; 53, identifier:priority; 54, call; 55, identifier:trigger; 56, identifier:triggers; 57, block; 58, identifier:self; 59, identifier:sorted; 60, identifier:self; 61, identifier:_triggers; 62, attribute; 63, argument_list; 64, identifier:atomics; 65, list_comprehension; 66, identifier:wildcards; 67, list_comprehension; 68, identifier:atomics; 69, call; 70, identifier:wildcards; 71, call; 72, subscript; 73, binary_operator:atomics + wildcards; 74, identifier:self; 75, identifier:_triggers; 76, identifier:sorted; 77, argument_list; 78, expression_statement; 79, attribute; 80, identifier:debug; 81, call; 82, identifier:trigger; 83, for_in_clause; 84, if_clause; 85, identifier:trigger; 86, for_in_clause; 87, if_clause; 88, identifier:sorted; 89, argument_list; 90, identifier:sorted; 91, argument_list; 92, attribute; 93, identifier:priority; 94, identifier:atomics; 95, identifier:wildcards; 96, call; 97, keyword_argument; 98, call; 99, identifier:self; 100, identifier:_log; 101, attribute; 102, argument_list; 103, identifier:trigger; 104, identifier:triggers; 105, attribute; 106, identifier:trigger; 107, identifier:triggers; 108, not_operator; 109, identifier:atomics; 110, keyword_argument; 111, keyword_argument; 112, identifier:wildcards; 113, keyword_argument; 114, keyword_argument; 115, identifier:self; 116, identifier:_triggers; 117, attribute; 118, argument_list; 119, identifier:reverse; 120, True; 121, attribute; 122, argument_list; 123, string; 124, identifier:format; 125, keyword_argument; 126, identifier:trigger; 127, identifier:pattern_is_atomic; 128, attribute; 129, identifier:key; 130, lambda; 131, identifier:reverse; 132, True; 133, identifier:key; 134, lambda; 135, identifier:reverse; 136, True; 137, attribute; 138, identifier:keys; 139, attribute; 140, identifier:append; 141, identifier:trigger; 142, string_content:Sorting priority {priority} triggers; 143, identifier:priority; 144, identifier:priority; 145, identifier:trigger; 146, identifier:pattern_is_atomic; 147, lambda_parameters; 148, tuple; 149, lambda_parameters; 150, tuple; 151, identifier:self; 152, identifier:_triggers; 153, identifier:self; 154, identifier:_sorted_triggers; 155, identifier:trigger; 156, attribute; 157, attribute; 158, identifier:trigger; 159, attribute; 160, attribute; 161, identifier:trigger; 162, identifier:pattern_words; 163, identifier:trigger; 164, identifier:pattern_len; 165, identifier:trigger; 166, identifier:pattern_words; 167, identifier:trigger; 168, identifier:pattern_len
code: def sort(self):
          """
          Sort triggers and their associated responses
          """
          # Sort triggers by word and character length first
          for priority, triggers in self._triggers.items():
              self._log.debug('Sorting priority {priority} triggers'.format(priority=priority))
  
              # Get and sort our atomic and wildcard patterns
              atomics = [trigger for trigger in triggers if trigger.pattern_is_atomic]
              wildcards = [trigger for trigger in triggers if not trigger.pattern_is_atomic]
  
              atomics = sorted(atomics, key=lambda trigger: (trigger.pattern_words, trigger.pattern_len), reverse=True)
              wildcards = sorted(wildcards, key=lambda trigger: (trigger.pattern_words, trigger.pattern_len),
                                 reverse=True)
  
              # Replace our sorted triggers
              self._triggers[priority] = atomics + wildcards
  
          # Finally, sort triggers by priority
          self._sorted_triggers = []
  
          for triggers in [self._triggers[priority] for priority in sorted(self._triggers.keys(), reverse=True)]:
              for trigger in triggers:
                  self._sorted_triggers.append(trigger)
  
          self.sorted = True