Skip to content

Instantly share code, notes, and snippets.

@techbelly
Created January 8, 2011 00:46
Show Gist options
  • Save techbelly/770380 to your computer and use it in GitHub Desktop.
Save techbelly/770380 to your computer and use it in GitHub Desktop.
#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