Skip to content

Instantly share code, notes, and snippets.

@funvill
Last active March 27, 2018 02:10
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 funvill/3fa37b439835603a7ea9a31ae833e433 to your computer and use it in GitHub Desktop.
Save funvill/3fa37b439835603a7ea9a31ae833e433 to your computer and use it in GitHub Desktop.
Working on kangaroo word generator in python.... not finished.
'''
Created by: Steven Smethurst
Created on: March 26, 2018
http://blog.abluestar.com
'''
from itertools import chain
from itertools import combinations
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
def powerset(iterable):
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
word_list = list()
''' with open('customDictionary.txt') as f: '''
with open('20k.txt') as f:
word_list = f.read().splitlines()
wordCount = len(word_list)
print("Dictionary word count: ", wordCount)
outputFile = open('result.txt', 'w')
progress = 0
for word in word_list:
progress+= 1
if word.startswith("#"):
continue
if len(word) < 5:
continue
print("progress: ", progress, "/", wordCount, ": ", end='')
subWordList = list()
for item in set(powerset(word)):
if len(item) < 4:
continue
combo = "".join(item)
if combo == word:
continue
if combo in word_list:
subWordList.append( combo )
if len(subWordList) > 0:
print(word, ", subWordCount: ", len(subWordList), ", ", end='')
print(word, ", subWordCount: ", len(subWordList), ", ", end='', file=outputFile)
for subword in set(subWordList):
outputFile.write("%s, " % subword)
print(subword, ", ", end='')
print("")
print("", file=outputFile)
print("\n\n\nDONE!!!!\n\n\n")
@funvill
Copy link
Author

funvill commented Mar 26, 2018

Example output:

abandonable: aba, aba, abb, aal, and, ann, ana, ado, ade, ana, aal, ale, ban, bad, ban, baa, bal, bae, bon, boa, bob, bal, bae, and, ann, ana, ado, ade, ana, aal, ale, non, noa, nob, nab, nae, don, dob, doe, dab, dal, dae, ona, one, obe, nab, nae, ale, able, anda, anon, anoa, anna, anal, anal, able, band, bane, bade, bane, baal, babe, bale, bone, bole, babe, bale, anda, anon, anoa, anna, anal, anal, able, none, done, doab, dobe, dole, dale, able, abdal, anole, annal, adobe, bando, banda, bande, banal, banal, anole, annal, adobe, noble, nable, nable, annale, bandle, annale, doable, abandon, donable, subWordCount: 102
abandoned: aba, and, ann, and, ado, ade, add, and, ban, bad, ban, bae, bad, bon, bod, bed, and, ann, and, ado, ade, add, and, non, nod, don, doe, dod, one, abed, anon, band, bane, band, bade, bane, band, bone, bond, anon, none, done, bando, bande, boned, banded, abandon, subWordCount: 47

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