you can make this a bit more compact with:

``tri_dict.setdefault(key_words, []).append(all_words[i + 2])``