-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdictionaries.py
More file actions
84 lines (48 loc) · 1.23 KB
/
dictionaries.py
File metadata and controls
84 lines (48 loc) · 1.23 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# simple dictionaries
phonebook = {}
phonebook["John"] = 938477566
phonebook["Jack"] = 938377264
phonebook["Jill"] = 947662781
print(phonebook)
# another way to create a dictionaries
phonebook = {
"John" : 938477566,
"Jack" : 938377264,
"Jill" : 947662781
}
print(phonebook)
# iterating over dictionaries
phonebook = {"John" : 938477566,"Jack" : 938377264,"Jill" : 947662781}
for name, number in phonebook.items():
print("Phone number of %s is %d" % (name, number))
# removing a value in dictionaries
phonebook = {
"John" : 938477566,
"Jack" : 938377264,
"Jill" : 947662781
}
del phonebook["John"]
print(phonebook)
# another way to removing a value in dictionaries
phonebook = {
"John" : 938477566,
"Jack" : 938377264,
"Jill" : 947662781
}
phonebook.pop("John")
print(phonebook)
'''
EXERCISE
Add "Jake" to the phonebook with the phone number 938273443, and remove Jill from the phonebook.
'''
# phonebook = {
# "John" : 938477566,
# "Jack" : 938377264,
# "Jill" : 947662781
# }
# # write your code here
# # testing code
# if "Jake" in phonebook:
# print("Jake is listed in the phonebook.")
# if "Jill" not in phonebook:
# print("Jill is not listed in the phonebook.")