def __init__(self, phrase_dict: Dict[(str, str)]):
    phrase_index = dict()
    for (spoken_form, written_form) in phrase_dict.items():
        words = spoken_form.split()
        if (not words):
            logging.warning(f'Found empty spoken form for written form{written_form}, ignored')
            continue
        (first_word, n_next) = (words[0], (len(words) - 1))
        phrase_index.setdefault(first_word, {}).setdefault(n_next, {})[tuple(words[1:])] = written_form
    self.phrase_index = {first_word: list(sorted(same_first_word.items(), key=(lambda x: (- x[0])))) for (first_word, same_first_word) in phrase_index.items()}
def __init__(self, phrase_dict: Dict[(str, str)]):
    phrase_index = dict()
    for (spoken_form, written_form) in phrase_dict.items():
        words = spoken_form.split()
        if (not words):
            logging.warning(f'Found empty spoken form for written form{written_form}, ignored')
            continue
        (first_word, n_next) = (words[0], (len(words) - 1))
        phrase_index.setdefault(first_word, {}).setdefault(n_next, {})[tuple(words[1:])] = written_form
    self.phrase_index = {first_word: list(sorted(same_first_word.items(), key=(lambda x: (- x[0])))) for (first_word, same_first_word) in phrase_index.items()}