def invert_dict(input_dict: dict, sort_keys: bool = False) -> dict:
    """Create a new dictionary swapping keys and values.

    Invert a given dictionary, creating a new dictionary where each key is
    created from a value of the original dictionary, and its value is the
    key that it was associated to in the original dictionary
    (e.g. invert_dict({1: ["A", "E"], 2: ["D", "G"]}) =
    {"A": 1, "E": 1, "D": 2, "G": 2}).
    It is also possible to return an inverted dictionary with keys in
    alphabetical order, although this makes little sense for intrinsically
    unordered data structures like dictionaries, but it may be useful when
    printing the results.

    Args:
        input_dict: original dictionary to be inverted
        sort_keys: sort the keys in the inverted dictionary in
            alphabetical order (default: False)

    Returns:
        new_dict: inverted dictionary
    """
    new_dict = {el: x for x in input_dict for el in input_dict[x]}
    if sort_keys:
        return {el: new_dict[el] for el in sorted(new_dict)}

    return new_dict