<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sort_trigger_set(triggers, exclude_previous=True, say=None):
 """Sort a group of triggers in optimal sorting order. The optimal sorting order is, briefly: * Atomic triggers (containing nothing but plain words and alternation groups) are on top, with triggers containing the most words coming first. Triggers with equal word counts are sorted by length, and then alphabetically if they have the same length. * Triggers containing optionals are sorted next, by word count like atomic triggers. * Triggers containing wildcards are next, with ``_`` (alphabetic) wildcards on top, then ``#`` (numeric) and finally ``*``. * At the bottom of the sorted list are triggers consisting of only a single wildcard, in the order: ``_``, ``#``, ``*``. Triggers that have ``{weight}`` tags are grouped together by weight value and sorted amongst themselves. Higher weighted groups are then ordered before lower weighted groups regardless of the normal sorting algorithm. Triggers that come from topics which inherit other topics are also sorted with higher priority than triggers from the inherited topics. Arguments: triggers ([]str):
 Array of triggers to sort. exclude_previous (bool):
 Create a sort buffer for 'previous' triggers. say (function):
 A reference to ``RiveScript._say()`` or provide your own function. """

    if say is None:
        say = lambda x: x

    # KEEP IN MIND: the `triggers` array is composed of array elements of the form
    # ["trigger text", pointer to trigger data]
    # So this code will use e.g. `trig[0]` when referring to the trigger text.

    # Create a list of trigger objects map.
    trigger_object_list = []
    for index, trig in enumerate(triggers):

        if exclude_previous and trig[1]["previous"]:
            continue

        pattern = trig[0]  # Extract only the text of the trigger, with possible tag of inherit

        # See if it has a weight tag
        match, weight = re.search(RE.weight, trig[0]), 0
        if match:  # Value of math is not None if there is a match.
            weight = int(match.group(1))  # Get the weight from the tag ``{weight}``

        # See if it has an inherits tag.
        match = re.search(RE.inherit, pattern)
        if match:
            inherit = int(match.group(1))  # Get inherit value from the tag ``{inherit}``
            say("\t\t\tTrigger belongs to a topic which inherits other topics: level=" + str(inherit))
            triggers[index][0] = pattern = re.sub(RE.inherit, "", pattern)  # Remove the inherit tag if any
        else:
            inherit = sys.maxsize  # If not found any inherit, set it to the maximum value, to place it last in the sort

        trigger_object_list.append(TriggerObj(pattern, index, weight, inherit))

    # Priority order of sorting criteria:
    # weight, inherit, is_empty, star, pound, under, option, wordcount, len, alphabet
    sorted_list = sorted(trigger_object_list,
                         key=attrgetter('weight', 'inherit', 'is_empty', 'star', 'pound',
                                        'under', 'option', 'wordcount', 'len', 'alphabet'))
    return [triggers[item.index] for item in sorted_list]