Last active
August 29, 2015 14:08
-
-
Save RyuKojiro/f30547f2970265ed94d7 to your computer and use it in GitHub Desktop.
Solves word jumbles
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/env python2.7 | |
import fileinput | |
import sys | |
if len(sys.argv) < 3: | |
print "Needs 2 arguments, first one is the word, second one is the list" | |
word = sys.argv[1] | |
dict = sys.argv[2] | |
# This determines if listB is a subset of listA | |
def listACanAccomodateListB(listA, listB): | |
tempLetters = listA[:] | |
for letter in listB: | |
if letter in tempLetters: | |
tempLetters.remove(letter) | |
else: | |
return False | |
return True | |
letters = list(word) | |
for line in fileinput.input(dict): | |
lineLetters = list(line)[:len(line) - 1] # Trim newlines | |
if listACanAccomodateListB(letters, lineLetters): | |
sys.stdout.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment