Skip to content

Instantly share code, notes, and snippets.

@kevinburke
Created February 1, 2011 04:16
Show Gist options
  • Save kevinburke/805401 to your computer and use it in GitHub Desktop.
Save kevinburke/805401 to your computer and use it in GitHub Desktop.
import copy
file_loc = '/usr/share/dict/words'
words = {}
with open(file_loc) as f:
word = f.readline()
while word != '':
words[word[:-1]] = True
word = f.readline()
while True:
print "What's the word?"
the_word = raw_input()
if the_word == "no":
break
while True:
print "How many letters?"
nums = raw_input().split()
if nums[0] == "no":
break
for num in nums:
valid = []
count = 0
for word in words.iterkeys():
count += 1
if len(word) == int(num):
chars = list(word)
new_word = list(copy.copy(the_word))
try:
for i in chars:
new_word.remove(i)
valid.append(word)
except ValueError:
continue
valid.sort()
for i in valid:
print i
print count
print len(words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment