Created
February 1, 2011 04:16
-
-
Save kevinburke/805401 to your computer and use it in GitHub Desktop.
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
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