Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
epequeno committed Feb 1, 2012
1 parent c3191e9 commit 3c22aa2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 87 deletions.
19 changes: 0 additions & 19 deletions ch09/9.06.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,9 @@
# Current Status: Complete

word_file = open('words.txt')

#def make_list():
# word_list = []
# for word in word_file:
# word_list.append(word.rstrip('\r\n'))
# return word_list
#
#word_list = make_list()

word_list = [word.rstrip('\r\n') for word in word_file]

def is_abecedarian(word):
return word == ''.join(sorted(word))

#def count_words():
# count = 0
# for word in word_list:
# if is_abecedarian(word):
# print word
# count += 1
# return count

#print count_words()

print len([word for word in word_list if is_abecedarian(word)])
6 changes: 0 additions & 6 deletions ch09/9.09.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@

# Current Status: Complete

#def make_ages():
# ages = []
# for i in range(1, 100):
# ages.append(str(i).zfill(2))
# return ages

ages = [str(i).zfill(2) for i in range(1, 100)]

def is_palindrome(x, y):
Expand Down
63 changes: 1 addition & 62 deletions ch12/12.05.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,65 +26,4 @@
# the words that are known to be reducible.
# You can see my solution at thinkpython.com/code/reducible.py.

# Current Status: Incomplete

word_file = open('words.txt')

def make_word_list():
word_list = []
for word in word_file:
word_list.append(word.strip('\n'))
word_list.append('a')
word_list.append('i')
word_list.sort(key=len, reverse=True)
return word_list

word_list = make_word_list()

def make_word_dict():
dict_ = {}
for word in word_list:
dict_[word] = None
return dict_

word_dict = make_word_dict()

def is_reduced(word):
return len(word) == 1 and (word == "i" or word == "a")

results = {}

def is_reducible(word):
test = []
for i in range(0, len(word)):
tmp_word = [letter for letter in word]
tmp_word.pop(i)
tmp_word = ''.join(tmp_word)
if tmp_word in word_dict:
test.append(tmp_word)
return len(test) > 0

def filter_reducible():
for word in word_list:
if is_reducible(word):
results[word] = True
else:
pass

filter_reducible()

def lol(x):
return x in word_dict

def wtf():
for word in word_dict:
for i in range(1, len(word)):
tmp = [letter for letter in word]
tmp.pop(i)
tmp = ''.join(tmp)
if lol(tmp):
results[word] = []
results[word].append(tmp)

wtf()
print results
# Current Status: Incomplete

0 comments on commit 3c22aa2

Please sign in to comment.