MCPcopy Index your code
hub / github.com/dabeaz-course/practical-python / read_portfolio

Function read_portfolio

Solutions/2_11/report.py:4–22  ·  view source on GitHub ↗

Read a stock portfolio file into a list of dictionaries with keys name, shares, and price.

(filename)

Source from the content-addressed store, hash-verified

2import csv
3
4def read_portfolio(filename):
5 '''
6 Read a stock portfolio file into a list of dictionaries with keys
7 name, shares, and price.
8 '''
9 portfolio = []
10 with open(filename) as f:
11 rows = csv.reader(f)
12 headers = next(rows)
13
14 for row in rows:
15 stock = {
16 'name' : row[0],
17 'shares' : int(row[1]),
18 'price' : float(row[2])
19 }
20 portfolio.append(stock)
21
22 return portfolio
23
24def read_prices(filename):
25 '''

Callers 1

report.pyFile · 0.70

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected