Skip to content

Commit

Permalink
merge .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
epequeno committed Sep 8, 2016
2 parents c0ec34e + 7c77954 commit ef97936
Show file tree
Hide file tree
Showing 11 changed files with 1,295 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.pyc
.solutions
venv2
.ThinkPy-Solutions
.ipynb_checkpoints
12 changes: 7 additions & 5 deletions ch08/8.02.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
prefixes = 'JKLMNOPQ'
suffix = 'ack'


def ducks():
for i in prefixes:
if i == "O" or i == "Q":
print i + "u" + suffix
for p in prefixes:
if p in ['O', 'Q']:
yield '{}uack'.format(p)
else:
print i + suffix
yield '{}ack'.format(p)

ducks()
for i in list(ducks()):
print i
26 changes: 17 additions & 9 deletions ch08/8.06.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,36 @@
@author: steven
"""

# word = 'banana'
# count = 0
# for letter in word:
# if letter == 'a':
# count = count + 1
# print count
# Rewrite this function so that instead of traversing the string, it uses the
# three-parameter version of find from the previous section.

# Current Status: Complete


def find(word, letter, index):
def find(letter, word, index):
while index < len(word):
if word[index] == letter:
return index
index += 1
return -1


def count(word, letter):
count = 0
def count(letter, word):
counter = 0
index = 0
while index < len(word):
if find(word, letter, index) != -1:
count += 1
index = find(word, letter, index) + 1
return count
result = find(letter, word, index)
if result == -1:
return counter
else:
counter += 1
index = result + 1
return counter

print count("banana", "a")
print count("n", "Think Python")
6 changes: 3 additions & 3 deletions ch08/8.07.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

# Current Status: Complete

word = "banana"
letter = "a"
w = "banana"
l = "a"


def count(word, letter):
return word.count(letter)

print count(word, letter)
print count(w, l)
Loading

0 comments on commit ef97936

Please sign in to comment.