forked from 0x90shell/Learn_Python_the_Hard_Way
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex40b.py
39 lines (25 loc) · 974 Bytes
/
ex40b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 msot important ever! study!
city_found = cities['_find'] (cities, state)
print city_found
"""
'CA' = key
More than one entry per key not allowed. Which means no duplicate key is allowed. When duplicate keys encountered during assignment, the last assignment wins.
Keys must be immutable. Which means you can use strings, numbers or tuples as dictionary keys but something like ['key'] is not allowed.
Continue with these:
http://docs.python.org/2/tutorial/datastructures.html
http://docs.python.org/2/library/stdtypes.html - mapping types
"""