Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are tasked with implementing a series of functions that perform various operations on dictionaries in Python. These functions will manipulate dictionaries that represent fruit

You are tasked with implementing a series of functions that perform various operations on dictionaries in Python. These functions will manipulate dictionaries that represent fruit prices and perform different operations as specified.
dictionary_operations(fruit_prices: dict, fruits: list)
Perform a series of operations on the given fruit_prices dictionary based on the fruits list:
Add fruits[0] with a cost of 3.
Modify the cost of fruits[1] to 2.
Increase the cost of fruits[2] by 2.
Delete fruits[3] from fruit_prices.
Print the price of fruits[4].
Print the names of fruits in fruit_prices as a sorted list.
Print the prices of fruits in fruit_prices as a sorted list.
increase_prices(fruit_prices: dict)-> None
Increase the prices of every fruit by 20% and round to two decimal places. Modify the dictionary in place.
dict_from_string(string: str, key_type, value_type)
Convert a string with comma-separated key-value pairs into a dictionary, converting the keys and values to the specified types.
dict_to_string(D: dict)-> str
Convert a dictionary back into a string with each key-value pair on a new line, using comprehensions.
Template code:
def dictionary_operations(fruit_prices:dict, fruits:list):
# add the fruit fruits[0] to fruit_prices with cost 3
...
order_print(fruit_prices) # this function is in the hidden code
# modify the cost of fruits[1] as 2 in fruit_prices
...
order_print(fruit_prices)
# increase the cost of fruits[2] by 2 in fruit_prices
...
order_print(fruit_prices)
# delete both key and value for fruits[3] from fruit_prices
...
order_print(fruit_prices)
# print the price of fruits[4]
...
# print the names of fruits in fruit prices as a list sorted in ascending order
...
# print the prices of the fruits as a list sorted in ascending order.
...
def increase_prices(fruit_prices:dict)-> None:
'''
Increase the prices of every fruit by 20 percent and round to two decimal places
Arguments:
fruit_prices: dict - fruit name as key and price as value
Return:
None - Do not return any thing - modify inplace
'''
...
def dict_from_string(string:str,key_type,value_type):
'''
Given a string where each line has a comma seperated key-value pair, create a dictionary out of it. Also convert the types of key and values to the given types.
Arguments:
string - str: string to be parsed
key_type - class: the data type of the keys
value_type - class: the data type of the values
Return:
D - dict: the output dictionary
'''
...
def dict_to_string(D:dict)-> str:
'''
Convert the given dictionary back to the string fromat produced by `dict_from_string`. Again, do not use loops or conditionals, use comprehensions.
'''
...

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

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions

Question

Watch help video the sum of 8x-2 and -3x^(2)-7. Answer: Submit

Answered: 1 week ago

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago