Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python program, in a file called SortCapitals.py, which will sort the following list of capital cities and their corresponding provinces into descending order,

Write a Python program, in a file called SortCapitals.py, which will sort the following list of capital cities and their corresponding provinces into descending order, based on the capital citys name. Use one of the sorting algorithms you have learned in this course.

capitals = ["Edmonton", "Victoria", "Winnipeg", "Fredericton", "St. John's", "Halifax", "Toronto", "Charlottetown", "Quebec City", "Regina", "Whitehorse", "Iqaluit", "Yellowknife"] provinces = ["AB", "BC", "MN", "NB", "NL", "NS", "ON", "PE", "QC", "SK", "YT", "NU", "NT"] 

Your program should output the unsorted lists and then the sorted lists, as well as the formatted and ordered cities and provinces as follows (be sure to keep the province in the correct order with its corresponding capital city):

Unsorted lists of capitals and provinces: ['Edmonton', 'Victoria', 'Winnipeg', 'Fredericton', "St. John's", 'Halifax', 'Toronto', 'Charlottetown', 'Quebec City', 'Regina', 'Whitehorse', 'Iqaluit', 'Yellowknife'] ['AB', 'BC', 'MN', 'NB', 'NL', 'NS', 'ON', 'PE', 'QC', 'SK', 'YT', 'NU', 'NT'] Sorted lists of capitals and provinces, in descending order of capital city: ['Yellowknife', 'Winnipeg', 'Whitehorse', 'Victoria', 'Toronto', "St. John's", 'Regina', 'Quebec City', 'Iqaluit', 'Halifax', 'Fredericton', 'Edmonton', 'Charlottetown'] ['NT', 'MN', 'YT', 'BC', 'ON', 'NL', 'SK', 'QC', 'NU', 'NS', 'NB', 'AB', 'PE'] Sorted and formatted list of capitals (and corresponding provinces): Yellowknife, NT Winnipeg, MN Whitehorse, YT Victoria, BC Toronto, ON St. John's, NL Regina, SK Quebec City, QC Iqaluit, NU Halifax, NS Fredericton, NB Edmonton, AB Charlottetown, PE

image text in transcribed

Write a Python program, in a file called sortCapitals.py, which will sort the following list of capital cities and their corresponding provinces into descending order, based on the capital city's name. Use one of the sorting algorithms you have learned in this course capitals ["Edmonton", "Victoria", "Winnipeg", "Fredericton", "St. John's", "Halifax", "Toronto", provinces ["AB", "BC", "MN", "NB", "NL", "NS", "ON", "PE", "QC", "SK", "YT", "NU", "NT"] "Charlottetown", "Quebec City", "Regina", "Whitehorse", "Iqaluit Your program should output the unsorted lists and then the sorted lists, as well as the formatted and ordered cities and provinces as follows (be sure to keep the province in the correct order with it's corresponding capital city): Unsorted lists of capitals and provinces: ['Edmonton', 'Victoria', 'Winnipeg, 'Fredericton', "St. John's 'Halifax', 'Toronto', "Charlottetown 'Quebec City 'Regina', 'Whitehorse', 'Iqaluit', 'Yellowk Sorted 1ists of capitals and provinces, in descending order of capital city: ['Yellowknife', 'Winnipeg, "Whitehorse', 'Victoria Toronto "St. John's Regina', "Quebec City 'Iqaluit' 'Halifax', Fredericton Edmonton "Charlotte Sorted and formatted list of capitals (and corresponding provinces): Yellowknife, NT Winnipeg, Whitehorse, YT Victoria, BC Toronto, ON St. John's, NL Regina, SK Quebec City, Qc Iqaluit, NU Halifax, NS Fredericton, NB Edmonton, AB Charlottetown, PE MN

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions