We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 322df65 commit f6902f9Copy full SHA for f6902f9
sampledicts.py
@@ -0,0 +1,23 @@
1
+# SAMPLE CODE TO UNDERSTAND THE CONCEPT OF DICTIONARIES IN PYTHON
2
+
3
+cities = {'CA': 'San Francisco', 'MI': 'Detroit','FL': 'Jacksonville'}
4
+cities['NY'] = 'New York'
5
+cities['OR'] = 'Portland'
6
+def find_city(themap, state):
7
+ if state in themap:
8
+ return themap[state]
9
+ else:
10
+ return "Not found."
11
+# ok pay attention!
12
13
+cities['_find'] = find_city
14
15
+while True:
16
+ print "State? (ENTER to quit)",
17
+ state = raw_input("> ")
18
+ if not state: break
19
20
+# this line is the most important ever! study!
21
22
+ city_found = cities['_find'](cities, state)
23
+ print city_found
0 commit comments