Question: PYTHON The high_volume function takes a dict argument in the form of the data structure above,(a dict whose keys are dates (str), each associated with
PYTHON The high_volume function takes a dict argument in the form of the data structure above,(a dict whose keys are dates (str), each associated with an inner dict whose keys are drug names (str)and whose associated value is a tuple of int transactions)and returns a list of drug names (str).This list must be ordered by decreasing volume: if two drugs have the same volume, the drugs appear in alphabetical order. We define volume as the total number of pills either received or delivered: e.g, if the transactions are the tuple (4, 2, -3) the volume is 4+2+3 = 9 (count the positive of each value in the transactions).So calling this function with the db1 dictionary shown above high_volume( db1 )returns the list ['Azor', 'Caml', 'Depr', 'Benz']The volumes of these are 115, 11, 11, and 9 respectively: because Caml and Depr have the same volume, they appear in the list in alphabetical order.
if prompt.for_bool('Test high_volume?', True): db1 = {'2016-04-01': {'Benz': (4, 2, -3), 'Azor': (100, -3, -3, 1)}, '2016-04-02': {'Depr': (4, -7), 'Azor': (-3, -3, 2), 'Caml': (6, -2, -3)}} print(' argument =',db1) answer = high_volume(db1) print(' answer =', answer) check(answer,['Azor', 'Caml', 'Depr', 'Benz'] ) db1 = {'2016-04-02': {'Azor': (-5, -2, 3, -1, -7), 'Efos': (-3, 20, -7), 'Caml': (4, 6, -2, 20, -8, -3)}, '2016-04-03': {'Benz': (-4, 16), 'Azor': (-4,), 'Efos': (4, 1, 30), 'Caml': (-2, -2, -3, -2)}, '2016-04-01': {'Benz': (4, 2, -3, 20), 'Depr': (30, -2, -5, -10, -2), 'Azor': (20, -3, -3, 1), 'Efos': (4, -7), 'Caml': (4, 6, -2, 1, -8, -3)}} print(' argument =',db1) answer = high_volume(db1) print(' answer =', answer) check(answer, ['Caml', 'Efos', 'Azor', 'Benz', 'Depr'])
def high_volume(db : {str:{str:(int,)}}) -> [str]:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
