Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON 4: Details of transaction_summary: The transaction_summary function takes a dict argument in the form of the data structure above. (a dict whose keys are

PYTHON

4: Details of transaction_summary: The transaction_summary 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 3-tuples containing a drug name (str), followed by the total number of times that drug was received, followed by the total number of times the drug was distributed. This list must be ordered alphabetically by the names of the drugs. So calling this function with the db1 dictionary shown above transaction_summary ( db1 ) returns the list [('Azor', 3, 4), ('Benz', 2, 1), ('Caml', 1, 2), ('Depr', 1, 1)] Note that Azor's transaction tuples are (100, -3, -3, 1) and (-3, -3, 2), showing 3 receipts (100, 1, and 2); and 4 distributions (-3, -3, -3, and -3).

if __name__ == '__main__': 
if prompt.for_bool('Test transaction_summary?', 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 = transaction_summary(db1)  print(' answer =', answer)  check(answer, [('Azor', 3, 4), ('Benz', 2, 1), ('Caml', 1, 2), ('Depr', 1, 1)])    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 = transaction_summary(db1)  print(' answer =', answer)  check(answer, [('Azor', 3, 7), ('Benz', 4, 2), ('Caml', 6, 10), ('Depr', 1, 4), ('Efos', 5, 3)])  
def transaction_summary(db : {str:{str:(int,)}}) -> [(str,int,int)]: 

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

More Books

Students also viewed these Databases questions