-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionary_peak_solved.py
38 lines (33 loc) · 1.47 KB
/
dictionary_peak_solved.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
# The exercise uses the following "peak" dictionary:
peak = {
"name": "Castle Peak",
"height": 14264,
"summit_log": [],
"cell_reception": {"AT&T": "no reception", "T-Mobile": "poor"},
}
# Without touching the original variable declaration (above)...
# Add a "range" key to peak and set it equal to "Elk Mountains"
peak["range"] = "Elk Mountains"
# Add a "first_climbed" key to peak and set it equal to 1873
peak["first_climbed"] = 1873
# Whoops, there's a mistake with the peak "height". Update it to 14265
peak["height"] = 14265
# Add a "Verizon" to the "cell_reception" dict and set it equal to "good"
peak["cell_reception"]["Verizon"] = "good"
# You just summited the peak! Add your name to the "summit_log" list
peak["summit_log"].append("Joan Camps")
# Let's rename "height" to "elevation":
# Remove "height" from the dict and store the result in a variable.
deleted_value = peak.pop("height")
# Use the value for "height" and store it in the dict under they key "elevation"
peak["elevation"] = deleted_value
# Loop over the values in the dictionary and print them all out. Don't ask why, just do it :)
for value in peak.values():
print(value)
# Loop over the keys AND values in the dictionary and print them all out in the following format:
# key -> value
# (print an arrow between each pair)
for key, value in peak.items():
print(key, "->", value)
# A huge earthquake/meteor/forestfire/tsunami has destroyed the peak. Please empty out the entire dictionary.
peak.clear()