code: def sort(self):
          for priority, triggers in self._triggers.items():
              self._log.debug('Sorting priority {priority} triggers'.format(priority=priority))
              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)
              self._triggers[priority] = atomics + wildcards
          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