Create two functions that you can use for a dictionary manager: 1. remove_item(dictionary,key): a function that removes...

90.2K

Verified Solution

Question

Programming

Create two functions that you can use for a dictionarymanager:

1. remove_item(dictionary,key): a function that removes the itemwith the supplied key from the dictionary, if it exits. If theinput key doesn’t exist in the dictionary, print out a messagesaying that the new item has not been removed because there is nomatching key in the dictionary. Your function should not produce aPython error if the item does not exist;

2. add_new_item(dictionary,key,value): a function that adds anew item to the dictionary (using the input key and value)if there is no existing item in the dictionary with thesupplied key. If the input key already exists in the dictionary,print out a message saying that the new item has not been addedbecause there is already a matching key in the dictionary. NoPython error should be raised by this fuction if the key alreadyexists.

Test out your functions by creating a dictionary with severalitems and then doing four (4) things:

  1. removing an item that exist;

  2. removing an item that doesn’t exist;

  3. adding an item whose key doesn’t exist;

  4. adding an item whose key does exist;

Print out the contents of the dictionary after each of thesetests and include the output of running your code as a comment inyour submission.

We use python for this course

Answer & Explanation Solved by verified expert
4.1 Ratings (625 Votes)
SOURCE CODEpythonPlease follow the comments to better understand the codePlease look at the Screenshot below and use this code to copypasteThe code in the below screenshot is neatly indented for better understandingdef removeitemdictionary key Check if the key    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students