@@ -0,0 +1,1498 @@
+'''%0AAnalyze the relation of different wordlists and list the words in a%0Ahierarchical order.%0A'''%0Aimport json%0Aimport argparse%0Afrom collections import defaultdict%0A%0Aparser = argparse.ArgumentParser(__doc__)%0Aparser.add_argument('-l', '--wordlists', nargs='+',%0A                    help='list of wordlist json files')%0AFLAGS = parser.parse_args()%0A%0Awordlists = %5B%5D%0Awordcounts = defaultdict(lambda: 0)%0Amaxcount = 0%0Aallwords = set()%0A%0A# load the wordlists and count the frequency of each word%0Afor wordlist_path in FLAGS.wordlists:%0A    with open(wordlist_path) as f:%0A        wl_json = json.load(f)%0A%0A    if isinstance(wl_json, dict):%0A        wordlist = wl_json.keys()%0A    elif isinstance(wl_json, list):%0A        wordlist = wl_json%0A%0A    newwords = %5B%5D%0A    for word in wordlist:%0A        wordcounts%5Bword%5D += 1%0A        if maxcount %3C wordcounts%5Bword%5D:%0A            maxcount = wordcounts%5Bword%5D%0A%0A        # only obtain words not included in previous wordlists%0A        if word not in allwords:%0A            allwords.add(word)%0A            newwords.append(word)%0A%0A    wordlists.append(newwords)%0A%0A# group, sort and print%0Afor k, wordlist in enumerate(wordlists):%0A    print('Wordlist %7B%7D'.format(k))%0A    countwords = defaultdict(lambda: %5B%5D)%0A    for word in wordlist:%0A        countwords%5Bwordcounts%5Bword%5D%5D.append(word)%0A    wordgroups = sorted(countwords.items(), key=lambda x: x%5B0%5D, reverse=True)%0A    for lv, wordgroup_kv in enumerate(wordgroups):%0A        print('Level %7B%7D'.format(lv))%0A        print(' '.join(sorted(wordgroup_kv%5B1%5D)))%0A

add wordlist analyzer