Created
December 19, 2012 19:20
-
-
Save mtimkovich/4339646 to your computer and use it in GitHub Desktop.
Anagram program using the wordlist from http://www.isc.ro/en/commands/lists.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import collections | |
d = collections.defaultdict(list) | |
output = 0 | |
f = open("TWL06.txt") | |
for line in f.readlines(): | |
line = line.strip().lower() | |
signature = "".join(sorted(line)) | |
d[signature].append(line) | |
f.close() | |
for i, w in sorted(d.iteritems(), key=lambda (k, v): len(v), reverse=True): | |
print "{} ({}) => {}".format(i, len(w), ", ".join(w)) | |
if output < 2: | |
output += 1 | |
else: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment