-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the problems for the rest of the book
- Loading branch information
Showing
63 changed files
with
114,526 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Write a function that reads the words in words.txt and stores them as keys | ||
# in a dictionary. It doesn't matter what the values are. Then you can use | ||
# the in operator as a fast way to check whether a string is in the | ||
# dictionary. If you did Exercise 10.8, you can compare the speed of this | ||
# implementation with the list in operator and the bisection search. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Dictionaries have a method called get that takes a key and a default | ||
# value. If the key appears in the dictionary, get returns the | ||
# corresponding value; otherwise it returns the default value. | ||
# For example: | ||
# >>> h = histogram('a') | ||
# >>> print h | ||
# {'a': 1} | ||
# >>> h.get('a', 0) | ||
# 1 | ||
# >>> h.get('b', 0) | ||
# 0 | ||
# Use get to write histogram more concisely. You should be able to | ||
# eliminate the if statement |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Dictionaries have a method called keys that returns the keys of the | ||
# dictionary, in no particular order, as a list. | ||
# Modify print_hist to print the keys and their values in alphabetical order. | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Modify reverse_lookup so that it builds and returns a list of all keys | ||
# that map to v, or an empty list if there are none. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Read the documentation of the dictionary method setdefault and use it | ||
# to write a more concise version of invert_dict. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Run this version of fibonacci and the original with a range of parameters | ||
# and compare their run times. | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Exponentiation of large integers is the basis of common algorithms for | ||
# public-key encryption. Read the Wikipedia page on the RSA algorithm and | ||
# write functions to encode and decode messages. | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# If you did Exercise 10.5, you already have a function named | ||
# has_duplicates that takes a list as a parameter and returns True if | ||
# there is any object that appears more than once in the list. | ||
# Use a dictionary to write a faster, simpler version of has_duplicates. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Two words are "rotate pairs" if you can rotate one of them and get the | ||
# other (see rotate_word in Exercise 8.12). | ||
# Write a program that reads a wordlist and finds all the rotate pairs. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Here's another Puzzler from Car Talk : | ||
# This was sent in by a fellow named Dan O'Leary. He came upon a common one- | ||
# syllable, five-letter word recently that has the following unique property. | ||
# When you remove the first letter, the remaining letters form a homophone of | ||
# the original word, that is a word that sounds exactly the same. Replace the | ||
# first letter, that is, put it back and remove the second letter and the | ||
# result is yet another homophone of the original word. And the question is, | ||
# what's the word? | ||
# Now I'm going to give you an example that doesn't work. Let's look at the | ||
# five-letter word, 'wrack.' W-R-A-C-K, you know like to 'wrack with pain.' If | ||
# I remove the first letter, I am left with a four-letter word, 'R-A-C-K.' As | ||
# in, 'Holy cow, did you see the rack on that buck! It must have been a | ||
# nine-pointer!' It's a perfect homophone. If you put the 'w' back, and remove | ||
# the 'r,' instead, you're left with the word, 'wack,' which is a real word, | ||
# it's just not a homophone of the other two words. But there is, however, at | ||
# least one word that Dan and we know of, which will yield two homophones if | ||
# you remove either of the first two letters to make two, new four-letter words. # The question is, what's the word? | ||
# You can use the dictionary from Exercise 11.1 to check whether a string is in | ||
# the word list. | ||
# To check whether two words are homophones, you can use the CMU Pronouncing | ||
# Dictionary. You can download it from | ||
# www.speech.cs.cmu.edu/cgi-bin/cmudict or from thinkpython.com/code/c06d | ||
# and you can also download thinkpython.com/code/pronounce.py, which provides | ||
# a function named read_dictionary that reads the pronouncing dictionary and | ||
# returns a Python dictionary that maps from each word to a string that | ||
# describes its primary pronunciation. | ||
# Write a program that lists all the words that solve the Puzzler. You can see | ||
# my solution at thinkpython.com/code/homophone.py. | ||
|
||
|
||
|
Oops, something went wrong.