-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionary.py
42 lines (37 loc) · 1.21 KB
/
dictionary.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
39
40
41
42
# Nesting Dictionary in a Dictionary
travel_log = {
"France": {"cities_visited": ["Paris", "Lille", "Dijon"], "total_visits": 12},
"Germany": {
"cities_visited": ["Berlin", "Hamburg", "Stuttgart"],
"total_visits": 5,
},
}
# Nesting Dictionary in a List
travel_log = [
{
"country": "France",
"cities_visited": ["Paris", "Lille", "Dijon"],
"total_visits": 12,
},
{
"country": "Germany",
"cities_visited": ["Berlin", "Hamburg", "Stuttgart"],
"total_visits": 5,
},
]
country = input()
visits = int(input())
list_of_cities = eval(input())
travel_log = [
{"country": "France", "visits": 12, "cities": ["Paris", "Lille", "Dijon"]},
{"country": "Germany", "visits": 5, "cities": ["Berlin", "Hamburg", "Stuttgart"]},
]
def add_new_country(name, times_visited, cities_visited):
new_country = {}
new_country["country"] = name
new_country["visits"] = times_visited
new_country["cities"] = cities_visited
travel_log.append(new_country)
add_new_country(country, visits, list_of_cities)
print(f"I've been to {travel_log[2]['country']} {travel_log[2]['visits']} times.")
print(f"My favourite city was {travel_log[2]['cities'][0]}.")