Skip to content

Instantly share code, notes, and snippets.

@adaptives
Created September 28, 2011 10:03
Show Gist options
  • Select an option

  • Save adaptives/1247538 to your computer and use it in GitHub Desktop.

Select an option

Save adaptives/1247538 to your computer and use it in GitHub Desktop.
LPTHW Exercise 40
# 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