Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to create the codes of the following two functions below? unique_values(a_dict:dict)-> dict This function will receive a single dictionary parameter known as a_dict.a_dict will

How to create the codes of the following two functions below?

unique_values(a_dict:dict)-> dict

This function will receive a single dictionary parameter known as a_dict.a_dict will contain a single letter as a string and numbers as values. This function is supposed to search a_dict to find all values that appear only once in the a_dict. The function will construct another dictionary named to_ret. For all values that appear once ina_dict the function will add the value as a key in to_retand set the value of the key to the key of the value ina_dict (swap the key-value pairs, since a_dict contains letters to numbers, to_retwill contain Numbers to Letters). Finally, the function should returnto_ret.

Example:

a_dict: {'X': 2, 'Y': 5, 'N': 2, 'L': 2, 'W': 1, 'G': 0, 'R': 1}

Expected: {5: 'Y', 0: 'G'}

a_dict: {'Z': 3, 'P': 3, 'E': 2, 'G': 0, 'T': 5, 'L': 1, 'Q': 0}

to_ret: {2: 'E', 5: 'T', 1: 'L'}

a_dict: {'E': 3, 'X': 3}

to_ret: {}

a_dict: {'G': 3, 'D': 3, 'C': 4, 'Q': 1, 'H': 1, 'M': 2, 'Z': 1, 'W': 3}

to_ret: {4: 'C', 2: 'M'}

a_dict: {'O': 2, 'T': 1, 'L': 5, 'W': 5, 'Z': 4, 'M': 5, 'B': 4, 'D': 0, 'F': 3, 'E': 1}

to_ret: {2: 'O', 0: 'D', 3: 'F'}

-------------------------------------------------------------------------------------

dict_from_string(dict_str:str)->dict

This function will be given a single parameter, a string representing a dictionary. Your job is to convert the string into an actual dictionary and return the dictionary. Make sure all key-value pairs in the string exist in the newly created dictionary. The string will contain only numbers or single letters as key values pairs. Make sure all letters are kept as strings and all numbers are converted to integers in the newly created dictionary.

Example:

String Input: '{9: 'V', 'G': 0, 'M': 9, 'u': 3, 2: 'o', 8: 'u', 'q': 9, 'D': 1}'

Expected: {9: 'V', 'G': 0, 'M': 9, 'u': 3, 2: 'o', 8: 'u', 'q': 9, 'D': 1}

String Input: '{10: 'D', 1: 'Z', 5: 'a'}'

Expected: {10: 'D', 1: 'Z', 5: 'a'}

String Input: '{'M': 2, 'V': 0, 3: 'x', 6: 'J', 5: 'J', 7: 'T', 8: 'P', 4: 'q', 1: 'h'}'

Expected: {'M': 2, 'V': 0, 3: 'x', 6: 'J', 5: 'J', 7: 'T', 8: 'P', 4: 'q', 1: 'h'}

String Input: '{3: 'D', 10: 'T', 7: 'm', 'u': 9, 't': 5, 6: 'Z', 'H': 10, 'B': 6}'

Expected: {3: 'D', 10: 'T', 7: 'm', 'u': 9, 't': 5, 6: 'Z', 'H': 10, 'B': 6}

String Input: '{'q': 10, 6: 'O', 'm': 6}'

Expected: {'q': 10, 6: 'O', 'm': 6}

-----------------------------------------------------------------------------------------------

Thank you so much!!

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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Which north american country known as the sugar bowl of the world?

Answered: 1 week ago

Question

South America is the continent located in which hemisphere?

Answered: 1 week ago

Question

Which of the following connects the south america to north america?

Answered: 1 week ago

Question

Which of the following is the highest peak of South America?

Answered: 1 week ago