Skip to content

Instantly share code, notes, and snippets.

@mtimkovich
Created December 19, 2012 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtimkovich/4339646 to your computer and use it in GitHub Desktop.
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
#!/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