Country TLD ----------------------------------- Canada ca d) Add the key-value pair 'Sweden' and 'sw' (which is incorrect). e) Update the value for the key 'Sweden' to 'se'. f) Use a dictionary comprehension to reverse the keys and values. g) With the result of part (f), use a dictionary comprehension to convert the country names to all uppercase letters.
Python Programming -Dictionary Manipulations
Introduction:
Assignment requires function creation and creating and manipulating dictionaries. The assignment has two levels/parts
Instructions:
Part 1:
Using the following dictionary, which maps country names to Internet top-level domains (TLDs):
tlds = {'Canada' : 'ca', 'United States' : 'us', 'Mexico' : 'mx' }
perform the following tasks and display the results:
a) Check whether the dictionary contains the key 'Canada'.
b) Check whether the dictionary contains the key 'France'.
c) Iterate through the key-value pairs and display them in two-column format.
(for step c, make sure dictionary content is displayed in tabular format as shown in example below)
Country TLD
-----------------------------------
Canada ca
d) Add the key-value pair 'Sweden' and 'sw' (which is incorrect).
e) Update the value for the key 'Sweden' to 'se'.
f) Use a dictionary comprehension to reverse the keys and values.
g) With the result of part (f), use a dictionary comprehension to convert the country names to all uppercase letters.
Part 2
- Convert the program to a menu driven program. When program is executed, the following menu should be displayed
MENU
---------------------------------------
- Create dictionary
- Search for TLD
- Add to dictionary
- Update dictionary
- Display dictionary content
- Exit
For choice 1. User is prompt to enter dictionary values
For 2. User is to enter country name and TLD would be displayed
For 3. Prompt user for country name and TLD and add to dictionary
For 4. Prompt user to enter key and new TLD, update dictionary accordingly
For 5. Display content in tabular format
For 6. Terminate program
- (After every operation, menu is to be displayed again until user chooses to terminate by entering 6.)
Note: Write program Pseudocode (detail
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images