-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy path09_dictionaries.py
More file actions
58 lines (52 loc) · 1.51 KB
/
09_dictionaries.py
File metadata and controls
58 lines (52 loc) · 1.51 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
"""
Dictionaries are Python's implementation of associative arrays.
There's not much different with Python's version compared to what
you'll find in other languages (though you can also initialize and
populate dictionaries using comprehensions just like you can with
lists!).
The docs can be found here:
https://docs.python.org/3/tutorial/datastructures.html#dictionaries
For this exercise, you have a list of dictionaries. Each dictionary
has the following keys:
- lat: a signed integer representing a latitude value
- lon: a signed integer representing a longitude value
- name: a name string for this location
"""
waypoints = [
{
"lat": 43,
"lon": -121,
"name": "a place"
},
{
"lat": 41,
"lon": -123,
"name": "another place"
},
{
"lat": 43,
"lon": -122,
"name": "a third place"
}
]
# Add a new waypoint to the list
# YOUR CODE HERE
new_waypoint = {
'lat': 26,
'lon': -214,
'name': 'a fourth place'
}
waypoints.append(new_waypoint)
print(waypoints)
# Modify the dictionary with name "a place" such that its longitude
# value is -130 and change its name to "not a real place"
# Note: It's okay to access the dictionary using bracket notation on the
# waypoints list.
# YOUR CODE HERE
waypoints[0]['lon'] = -130
waypoints[0]['name'] = 'not a real place'
print(waypoints)
# Write a loop that prints out all the field values for all the waypoints
# YOUR CODE HERE
for x in range(len(waypoints)):
print(waypoints[x].values())