Skip to content

Instantly share code, notes, and snippets.

@stesh
Created January 16, 2013 22:31
Show Gist options
  • Select an option

  • Save stesh/4551577 to your computer and use it in GitHub Desktop.

Select an option

Save stesh/4551577 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
words = open('/usr/share/dict/words').read().splitlines()
sort = lambda s:''.join(sorted(s))
anagrams = {sort(w):[] for w in words}
for word in words:
anagrams[sort(word)].append(word)
while True:
print anagrams[sort(raw_input())]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment