12.07.2015 Views

Think Python - Denison University

Think Python - Denison University

Think Python - Denison University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

11.10. Exercises 113implementation: A way of performing acomputation.hashtable: The algorithm usedtoimplement <strong>Python</strong> dictionaries.hash function: A function used by ahashtable tocompute thelocation for akey.hashable: A type that has a hash function. Immutable types like integers, floats and strings arehashable; mutable types likelistsand dictionaries arenot.lookup: A dictionary operation that takes akey and finds the corresponding value.reverse lookup: A dictionary operation that takes a value and finds one or more keys that map toit.singleton: A list(orother sequence) withasingleelement.call graph: A diagram that shows every frame created during the execution of a program, with anarrow from each caller toeach callee.histogram: Aset of counters.memo: A computed value stored toavoid unnecessary futurecomputation.global variable: A variable defined outside a function. Global variables can be accessed from anyfunction.flag: Aboolean variable used toindicate whether acondition istrue.declaration: A statement likeglobalthat tellstheinterpreter something about avariable.11.10 ExercisesExercise 11.8 If you did Exercise 10.5, you already have a function named has_duplicates thattakes a list as a parameter and returns True if there is any object that appears more than once in thelist.Useadictionary towriteafaster,simpler version ofhas_duplicates.Exercise 11.9 Two words are “rotate pairs” if you can rotate one of them and get the other (seerotate_wordinExercise 8.12).Writeaprogram that reads awordlist and finds allthe rotatepairs.Exercise 11.10 Here’s another Puzzler from Car Talk 4 :This was sent in by a fellow named Dan O’Leary. He came upon a common onesyllable,five-letter word recently that has the following unique property. When youremove 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 backand remove the second letter and the result is yet another homophone of the originalword. And thequestion is,what’s the word?Now I’m going to give you an example that doesn’t work. Let’s look at the five-letterword, ‘wrack.’ W-R-A-C-K, you know like to ‘wrack with pain.’ If I remove the first4 www.cartalk.com/content/puzzler/transcripts/200717.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!