Using a wordlist of ~350k words from https://github.com/dwyl/english-words/blob/master/words.txt?raw=true
aewalto@laptop:~/tmp $ python words.py wordlist.txt
Processing 354526 words...
aaa
app
iii
oho
tea
eat
eer
eta
hoo
oooo
ppa
ate
tae
aet
ere
ooh
pap
ree
xxx
mmmm
import multiprocessing
import sys
import itertools
MIN_LENGTH = 3
CHUNK_SIZE = 10000
with open(sys.argv[-1], 'r') as f:
data = f.read()
DICTIONARY = [word.strip().lower() for word in data.split('\n') if len(word) >= MIN_LENGTH]
def is_valid(word):
for permutation in itertools.permutations(word):
permutation = ''.join(permutation)
if permutation not in DICTIONARY:
return False
return True
def run(chunk):
for word in chunk:
if is_valid(word):
print(word)
if __name__ == '__main__':
print("Processing {} words...".format(len(DICTIONARY)))
p = multiprocessing.Pool(8)
chunks = [DICTIONARY[i::int(len(DICTIONARY)/CHUNK_SIZE)] for i in range(int(len(DICTIONARY)/CHUNK_SIZE))]
p.map(run, chunks)