Skip to content

Instantly share code, notes, and snippets.

@avinashv
Last active March 18, 2021 21:09
Show Gist options
  • Select an option

  • Save avinashv/2444 to your computer and use it in GitHub Desktop.

Select an option

Save avinashv/2444 to your computer and use it in GitHub Desktop.
A command-line anagram solver using the Linux/OS X wordlist.
def anagram_solve(letters, words):
solution = [word.lower() for word in words if len(word) == len(letters)]
for letter in letters:
solution = [word for word in solution if letter in word and letters.count(letter) == word.count(letter)]
return solution
if __name__ == "__main__":
import sys
if len(sys.argv) == 1:
print("Usage: %s [anagram]" % sys.argv[0])
else:
words = [word.rstrip() for word in open('/usr/share/dict/words', 'r')]
for anagram in sys.argv[1:]:
print("%s: %s" % (anagram, " ".join(anagram_solve(anagram, words))))
@rafael-skodlar

Copy link
Copy Markdown

Avinash,
It's 2020, time to upgrade to Python 3.x
I found this while playing with anagrams.

Rafael

@avinashv

Copy link
Copy Markdown
Author

It's 2020, time to upgrade to Python 3.x

Honestly, I forgot about this code after 12 years! Thanks for the reminder. Easily updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment