Skip to content

Commit

Permalink
refactorin tuesday
Browse files Browse the repository at this point in the history
  • Loading branch information
epequeno committed Jun 26, 2012
1 parent e8fc98e commit 5af1d2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
36 changes: 20 additions & 16 deletions ch10/10.08.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,26 @@
# it's not.
# Or you could read the documentation of the bisect module and use that!

# Current Status: Incomplete
# Current Status: Complete

import bisect
word_list = [word.strip('\r\n') for word in open('words.txt')]

def make_list():
words = open('words.txt')
for line in words:
line = line.strip()
wordList = []
wordList = wordList.append(line)
print wordList
def bisect(myWord, myList):
original = myList
while True:
middle = len(myList) / 2
if myWord > myList[middle]:
myList = myList[middle:]
elif myWord < myList[middle]:
myList = myList[:middle]
elif myWord == myList[middle]:
return original.index(myWord)

if len(myList) == 1:
if myWord != myList[:]:
return None
else:
return original.index(myWord)


make_list()


def is_in_list(make_list):
print make_list()

#is_in_list(make_list())
print bisect("steven", word_list)
20 changes: 2 additions & 18 deletions ch10/10.09.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,10 @@

# Current Status: Complete

word_file = open('words.txt')

def make_list():
list_ = []
for word in word_file:
list_.append(word.strip('\r\n'))
return list_

word_list = make_list()

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

word_dict = make_dict()
word_dict = {word.strip('\r\n') : None for word in open('words.txt')}

def find_rev_pairs():
for word in word_list:
for word in word_dict:
if word[::-1] in word_dict:
print word, word[::-1]

Expand Down

0 comments on commit 5af1d2c

Please sign in to comment.