Skip to content

Instantly share code, notes, and snippets.

@zTrix
Created February 7, 2014 14:22
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 zTrix/8863461 to your computer and use it in GitHub Desktop.
Save zTrix/8863461 to your computer and use it in GitHub Desktop.
#!/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