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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 8PP: (Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays...
icon
Related questions
Question

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 

  1. 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 algorithm) and add it as a comment block to the submitted program. 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT