Created
September 28, 2011 10:03
-
-
Save adaptives/1247538 to your computer and use it in GitHub Desktop.
LPTHW Exercise 40
This file contains hidden or 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
| # LPTHW Exercise 40 | |
| cities = {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'} | |
| cities['NY'] = 'New York' | |
| cities['OR'] = 'Portland' | |
| def find_city(themap, state): | |
| if state in themap: | |
| return themap[state] | |
| else: | |
| return "Not Found" | |
| # ok pay attention! | |
| cities['_find'] = find_city | |
| while True: | |
| print "State? (ENTER to quit)", | |
| state = raw_input("> ") | |
| if not state: break | |
| # this line is the most important ever! study! | |
| city_found = cities['_find'](cities, state) | |
| print city_found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment