Ana sayfa
/
Teknoloji
/
Part 3 (30pts) Write Python statements that will create a set of countries from the dictionary of cities and print the countries in sorted order as seen in the sample run below. Hint: Create a list from the set of countries, then sort this list. Part 3: Countr ies: Brazil . China France Italy Japan Turkiye UK USA

Soru

Part 3 (30pts)
Write Python statements that will create a set of countries from the dictionary of cities and print the
countries in sorted order as seen in the sample run below.
Hint: Create a list from the set of countries, then sort this list.
Part 3:
Countr ies: Brazil . China France Italy Japan Turkiye UK USA

Part 3 (30pts) Write Python statements that will create a set of countries from the dictionary of cities and print the countries in sorted order as seen in the sample run below. Hint: Create a list from the set of countries, then sort this list. Part 3: Countr ies: Brazil . China France Italy Japan Turkiye UK USA

Çözüm

4.4346 Voting
avatar
Janset
Usta · 5 yıl öğretmeni
Uzman doğrulaması

Cevap

Here is the Python code that will create a set of countries from the dictionary of cities and print the countries in sorted order:<br /><br />```python<br /># Dictionary of cities<br />cities = {<br /> "Brazil": "Brasilia",<br /> "China": "Beijing",<br /> "France": "Paris",<br /> "Italy": "Rome",<br /> "Japan": "Tokyo",<br /> "Turkiye": "Ankara",<br /> "UK": "London",<br /> "USA": "Washington D.C."<br />}<br /><br /># Create a set of countries<br />countries = set(cities.keys())<br /><br /># Print the countries in sorted order<br />sorted_countries = sorted(countries)<br />print("Countries:", ", ".join(sorted_countries))<br />```<br /><br />Sample output:<br />```<br />Countries: Brazil, China, France, Italy, Japan, Turkiye, UK, USA<br />```
Derecelendirmek için tıklayın: