Skip to content

Instantly share code, notes, and snippets.

@RyuKojiro
Last active August 29, 2015 14:08
Show Gist options
  • Save RyuKojiro/f30547f2970265ed94d7 to your computer and use it in GitHub Desktop.
Save RyuKojiro/f30547f2970265ed94d7 to your computer and use it in GitHub Desktop.
Solves word jumbles
#!/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