-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaries.py
More file actions
39 lines (28 loc) · 896 Bytes
/
Dictionaries.py
File metadata and controls
39 lines (28 loc) · 896 Bytes
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
# Program to demonstrate dictionaries in Python
# Canadian House of Commons
CanadaHoC = {"Liberals": 158, "Conservatives": 119, "Bloc Québécois": 32, "New Democrats": 25, "Greens": 2}
# Array with leftist parties
CanadaLeft = {"Liberals": 0, "New Democrats": 0, "Greens": 0}
# Print dictionary
print(CanadaHoC)
# Print type
print(type(CanadaHoC))
# Print keys
print(CanadaHoC.keys())
# Print values
print(CanadaHoC.values())
# Print items
print(CanadaHoC.items())
# Add item and print updated dictionary
CanadaHoC["Republicans"] = 0
print(CanadaHoC)
# Change existing item, display, and change back
CanadaHoC["Conservatives"] = 120
print(CanadaHoC)
CanadaHoC["Conservatives"] = 119
# Update dictionary and print
CanadaLeft.update(CanadaHoC)
print(CanadaLeft)
# Pop value and display dictionary again
CanadaHoC.pop("Republicans")
print(CanadaHoC)