Created
January 8, 2011 00:32
-
-
Save techbelly/770367 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
words = (w.strip().lower() for w in open('/usr/share/dict/words')) | |
#words = "now is the time for all good lal men godo".split() | |
def charsorted(word): | |
return "".join(sorted(list(word))) | |
results = dict() | |
for word,index in ((word,charsorted(word)) for word in words): | |
if index not in results: | |
results[index] = [] | |
results[index].append(word) | |
anagrams = (anagrams for anagrams in results.itervalues() if len(anagrams)>1) | |
for i,anagram in enumerate(anagrams,1): | |
print i," ".join(anagram) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment