Skip to content

Instantly share code, notes, and snippets.

@edesdan
Last active November 14, 2018 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edesdan/35482cf5e33362248489199e22134e8a to your computer and use it in GitHub Desktop.
Save edesdan/35482cf5e33362248489199e22134e8a to your computer and use it in GitHub Desktop.
Given a word as argument this little program written in python finds all the permutations that have a meaning in the en_US dictionary
#!/usr/bin/python
import sys
import pprint
from PyDictionary import PyDictionary
import itertools
def check(wordToCheck):
meaning = dictionary.meaning(wordToCheck)
if meaning:
pp.pprint(meaning)
results[wordToCheck] = meaning
if not meaning:
print("I'm sorry I couldn't find the meaning of the word "+ wordToCheck)
# MAIN
results = {}
pp = pprint.PrettyPrinter(indent=4)
word = sys.argv[1]
dictionary=PyDictionary()
permutations = list(set(itertools.permutations([ch for ch in word])))
print ("Checking " + str(len(permutations)) + " unique permutations")
for item in permutations:
permWord = ''.join(item)
print ("Check: " + permWord)
check(permWord)
print ("Found " +str(len(results))+ " results from " +str(len(permutations)) + " permutations:")
pp.pprint(results)
@edesdan
Copy link
Author

edesdan commented Nov 14, 2018

In order for this to work you need to install PyDictionary module available via pip (or pip3):

sudo pip3 install PyDictionary

@edesdan
Copy link
Author

edesdan commented Nov 14, 2018

you can also change this line:

meaning = dictionary.meaning(wordToCheck)

with this:

meaning = dictionary.googlemeaning(wordToCheck)

to check results from google instead of from a classic dictionary.

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