Last active
November 14, 2018 01:06
-
-
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
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
#!/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) |
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
In order for this to work you need to install PyDictionary module available via pip (or pip3):
sudo pip3 install PyDictionary