Created
October 23, 2018 03:16
-
-
Save shawnma/862448cc3d98fec292230b3fe39bf779 to your computer and use it in GitHub Desktop.
permutations of words
This file contains hidden or 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
import copy, sys | |
words = set() | |
def load(): | |
for f in open('words.txt').readlines(): | |
words.add(f.strip()) | |
# | |
# sr - string | |
# all - output set | |
# remaining - reminaing array | |
def perm(sr, all, remaining): | |
for c in remaining: | |
nw = sr + c | |
if (len(nw)>2): | |
all.add(nw) | |
p = copy.copy(remaining) | |
p.remove(c) | |
perm(nw, all, p) | |
s = set() | |
load() | |
perm('', s, [f for f in sys.argv[1]]) | |
for f in s.intersection(words): print f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment