Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON 4b. (2 pts) Define the summary function, which takes as arguments a database (dict) and a dict of current stock prices. It returns a

image text in transcribed

image text in transcribed

image text in transcribed

PYTHON

4b. (2 pts) Define the summary function, which takes as arguments a database (dict) and a dict of current stock prices. It returns a dictionary (dict or defaultdict) whose keys are client names (str) whose associated values are 2-tuples: the first index is a dictionary (dict or defaultdict) whose keys are stock names (str) and values are the number of shares (int) the client owns. The second index is the amount of money (int) the portfolio is worth (the sum of the number of shares of each stock multiplied by its current price). Assume each client starts with no shares of any stocks, and if a client owns 0 shares of a stock, the stock should not appear in the client's dictionary. Recall positive numbers are a purchase of the stock and negative numbers a sale of the stock. E.g., if db is the database above, calling summary(db, {'IBM':65, 'Intel':60, 'Dell':55, 'Apple':70}) would return { Carl': ({'Intel': 20, 'Dell': 20, 'Apple': 20), 3700), "Barb': (('IBM': 40), 2600), 'Alan': [{'Intel': 20, 'Apple': 80), 6800), "Dawn': (l'Apple': 40), 2800) } # Note: the keys in this dicts are not specified in alphabetical order db1 = { "Carl': (('Intel', 50, 40), ('Dell', 20, 50), ('Intel', -10, 60), ('Apple', 20, 55)], Barb': [C'Intel', 20, 40), ('Intel', -10, 45), ('IBM', 40, 30), ('Intel', -10, 35)], Alan': [('Intel', 20, 10), ('Dell', 10, 50), ('Apple', 80, 80), ('Dell', -10, 55)], "Dawn': (('Apple', 40, 80), ('Apple', 40, 85), ('Apple', -40, 90)] } db2 = { "Hope': (('Intel', 30, 40), ('Dell', 20, 50), ('IBM', 10, 80), ('Apple', 20, 50), ('QlCom', 20, 20)], *Carl': [('QlCom', 30, 22), ('QLCom', 20, 23), ('QlCom', -20, 25), ('QlCom', -30, 28)], *Barb': [('Intel', 80, 42), ('Intel', -80, 45), ('Intel', 90, 28)], Fran': [('BrCom', 210, 62), ('BrCom', -20, 64), ('BrCom', -10, 66), ('BrCom', 10, 55)], Alan': (('Intel', 20, 10), ('Dell', 10, 50), ('Apple', 80, 80), ('Dell', -16, 55)), Gabe': (('IBM, 40, 82), ('QLCom', 80, 25), ('IBM", -20, 84), ('BrCom', 50, 65), ('QlCom', -40, 28)), "Dawn': (Apple', 40, 92), ('Apple', 40, 98), ('Apple', -40, 92)], 'Evan': (('Apple', 50, 92), ('Dell', 20, 50), ('Apple', -10,95), ('Apple', 20, 95), ('Dell', -20, 90)] e def summary(db: {str: [(str, int, int)]}; prices: {str: int}) -> {str: ({str: int), int)}: pass

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

Which of these influenced your life most dramatically?

Answered: 1 week ago

Question

What roles have these individuals played in your life?

Answered: 1 week ago