mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Add Word Generator
This commit is contained in:
parent
2c1cfb62f5
commit
2a1b863920
10
Word-generator/README.md
Normal file
10
Word-generator/README.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Word Generator
|
||||||
|
|
||||||
|
## Description
|
||||||
|
A python script that generates english words that contain 2 or more letters from input
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Just run gen.py and type in some letters
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
Python 3
|
45333
Word-generator/dictionary.txt
Normal file
45333
Word-generator/dictionary.txt
Normal file
File diff suppressed because it is too large
Load Diff
33
Word-generator/gen.py
Normal file
33
Word-generator/gen.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
def getDict(file):
|
||||||
|
words = set()
|
||||||
|
with open(file) as d:
|
||||||
|
for w in d.read().split("\n"):
|
||||||
|
words.add(w.lower())
|
||||||
|
return words
|
||||||
|
|
||||||
|
def isEng(word):
|
||||||
|
englishWords = getDict("dictionary.txt")
|
||||||
|
if word in englishWords:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def permutations(xl, length = -1, res=[], output=[]):
|
||||||
|
if xl == [] or len(res) == length:
|
||||||
|
output.append(res)
|
||||||
|
return
|
||||||
|
for i in range(len(xl)):
|
||||||
|
permutations(xl[:i] + xl[i + 1:], length, res + [xl[i]], output)
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
found = set()
|
||||||
|
letters = [i for i in input("Choose letters: ")]
|
||||||
|
for sz in range(2, len(letters)+1):
|
||||||
|
print("\nSize:", sz, "letters")
|
||||||
|
for comb in permutations(letters, sz ,[], []):
|
||||||
|
if isEng("".join(comb)) and not "".join(comb) in found:
|
||||||
|
print("Found word:", "".join(comb))
|
||||||
|
found.add("".join(comb))
|
||||||
|
print()
|
||||||
|
|
13
Word-generator/isEng.py
Normal file
13
Word-generator/isEng.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
def getDict(file):
|
||||||
|
words = set()
|
||||||
|
with open(file) as d:
|
||||||
|
for w in d.read().split("\n"):
|
||||||
|
words.add(w.lower())
|
||||||
|
return words
|
||||||
|
|
||||||
|
def isEng(word):
|
||||||
|
englishWords = getDict("dictionary.txt")
|
||||||
|
if word in englishWords:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
print(isEng("boot"))
|
Loading…
Reference in New Issue
Block a user