Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
import os, sys
di = open(sys.argv[1], 'r')
letters = sys.argv[2]
musthave = None
if len(sys.argv) > 3:
musthave = sys.argv[3]
def check(word):
ary = [letters[i] for i in range(len(letters))]
must = []
if musthave:
must = [musthave[i] for i in range(len(musthave))]
for i in range(len(word)):
if ary.count(word[i]) > 0:
ary.remove(word[i])
if must.count(word[i]) > 0:
must.remove(word[i])
else:
return False
return len(must) == 0
rs = []
for line in di:
word = line[:-1]
if len(word) < 2:
continue
if check(word):
rs.append(word)
rs.sort(key=len)
for item in rs:
print item, ''.join(sorted(item))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment