-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython Dictionary.py
More file actions
54 lines (49 loc) · 1.63 KB
/
Copy pathPython Dictionary.py
File metadata and controls
54 lines (49 loc) · 1.63 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
"""Time to play with Python dictionaries!
You're going to work on a dictionary that
stores cities by country and continent.
One is done for you - the city of Mountain
View is in the USA, which is in North America.
You need to add the cities listed below by
modifying the structure.
Then, you should print out the values specified
by looking them up in the structure.
Cities to add:
Bangalore (India, Asia)
Atlanta (USA, North America)
Cairo (Egypt, Africa)
Shanghai (China, Asia)"""
locations = {'North America': {'USA': ['Mountain View']}}
locations['North America']['USA'].append('Atlanta')
locations['Asia']={'India':['Bangalore']}
locations['Asia']['China']=['Shanghai']
locations['Africa']={'Egypt':['Cairo']}
locations = {'North America': {'USA': ['Mountain View']}}
locations['North America']['USA'].append('Atlanta')
locations['Asia']={'India':['Bangalore']}
locations['Asia']['China']=['Shanghai']
locations['Africa']={'Egypt':['Cairo']}
sorted_american_cities=sorted(locations['North America']['USA'])
print (1)
for city in sorted_american_cities:
print(city)
print (2)
asian_cities = []
for countries, cities in locations['Asia'].items():
city_country = cities[0] + " - " + countries
asian_cities.append(city_country)
sorted_asian_cities = sorted(asian_cities)
for city in sorted_asian_cities:
print (city)
"""Print the following (using "print").
1. A list of all cities in the USA in
alphabetic order.
2. All cities in Asia, in alphabetic
order, next to the name of the country.
In your output, label each answer with a number
so it looks like this:
1
American City
American City
2
Asian City - Country
Asian City - Country"""