[Tutor] dict['_find']
Max Niederhofer
max at niecap.com
Sun Feb 20 05:14:46 CET 2011
Hello all,
first post, please be gentle. I'm having serious trouble finding an
alternative for the deprecated find module for dictionaries.
The code (from Zed Shaw's Hard Way, exercise 40) goes something like
this. Hope indentation survives.
cities = {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'}
def find_city(themap, state):
if state in themap:
return themap[state]
else:
return "Not found."
cities['_find'] = find_city
while True:
print "State? (ENTER to quit)",
state = raw_input("> ")
if not state: break
city_found = cities['_find'](cities, state)
print city_found
My question is - how do I rewrite this using an alternate module given
find is deprecated? Grateful for all suggestions or pointers. For
reference, I'm using 2.6.1 on darwin.
Thanks so much for your help.
Best,
Max
--
Dr. Maximilian Niederhofer
Founder, Qwerly
http://qwerly.com/ | http://qwerly.com/max
+44 78 3783 8227
More information about the Tutor
mailing list