from collections import defaultdict from pprint import pprint from dictionary import GROUPS, toki_pona_en def main(): counter = dict() for word in toki_pona_en.keys(): counter[word] = [] for group_name, words in GROUPS.items(): for word in words: counter[word].append(group_name.split('GROUP_')[1]) pprint(sorted(counter.items(), key=lambda x: len(x[1]), reverse=True)) if __name__ == '__main__': main()