Created
January 8, 2011 00:46
-
-
Save techbelly/770380 to your computer and use it in GitHub Desktop.
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
#words = (w.strip().lower() for w in open('wordlist.txt')) | |
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 str(sorted(word)) | |
results = dict() | |
for word,index in ((word,charsorted(word)) for word in words): | |
results.setdefault(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