-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforloops.py
More file actions
46 lines (33 loc) · 1.18 KB
/
forloops.py
File metadata and controls
46 lines (33 loc) · 1.18 KB
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
40
41
42
43
44
45
46
# Dictionaries in Python; exercise from Chapter 3 in "Learn Python Quickly"
# Have a few for loops in these that can print values vertically
print ("Creating dictionary now.")
telnums = {}
print ("Populating the dictionary.")
telnums = {"Bob":"867-5209", "Cheryl":"555-3434", "Tammy":"765-3232", "Susan":"876-4545", "Caroline":"987-2312"}
print ("The dictionary is: ")
print (telnums.items())
print ("The dictionary printed vertically is: ")
for alpha in telnums:
print(alpha, telnums[alpha] )
print ("Now we are going to update Bob.")
telnums["Bob"] = "786-9025"
print ("Changing Bob:")
print (telnums.items())
print ("Now we are going to retrieve a phone number for Bob:")
print (telnums ["Bob"] )
print ("Deleting Bob from dictionary.")
del telnums["Bob"]
print ("The dictionary now reads: ")
print (telnums.items() )
print ("Listing the dictionary key names:")
print (telnums.keys() )
print ("Printing the key names vertically: ")
for item in telnums:
print (item)
print ("Vertical list of the phone numbers: ")
for item in telnums:
print (telnums[item])
print ("Empty the dictionary: ")
telnums.clear()
print ("Checking to see if it has been cleared: ")
print (telnums.items() )