12.07.2015 Views

Think Python - Denison University

Think Python - Denison University

Think Python - Denison University

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

114 Chapter 11. Dictionariesletter, I am left with a four-letter word, ’R-A-C-K.’ As in, ‘Holy cow, did you see therack on that buck! It must have been a nine-pointer!’ It’s a perfect homophone. If youput the ‘w’ back, and remove the ‘r,’ instead, you’re left with the word, ‘wack,’ whichisareal word, it’sjust not ahomophone of theother twowords.Butthereis,however, atleastonewordthatDanandweknowof,whichwillyieldtwohomophones if you remove either of the first two letters to make two, new four-letterwords. The question is,what’s theword?You can use thedictionary from Exercise 11.1 tocheck whether astringisinthe wordlist.To check whether two words are homophones, you can use the CMU Pronouncing Dictionary. Youcan 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 providesa function named read_dictionary that reads the pronouncing dictionary and returns a <strong>Python</strong>dictionary that maps from each word toastringthat describes itsprimarypronunciation.Write a program that lists all the words that solve the Puzzler. You can see my solution atthinkpython.com/code/homophone.py.

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

Saved successfully!

Ooh no, something went wrong!