Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/dabeaz/python-cookbook
/ compute_cost
Function
compute_cost
src/1/mapping_names_to_sequence_elements/example1.py:7–12 ·
view source on GitHub ↗
(records)
Source
from the content-addressed store, hash-verified
5
Stock = namedtuple(
'Stock'
, [
'name'
,
'shares'
,
'price'
])
6
7
def
compute_cost(records):
8
total = 0.0
9
for
rec in records:
10
s = Stock(*rec)
11
total += s.shares * s.price
12
return
total
13
14
# Some Data
15
records = [
Callers
1
example1.py
File · 0.85
Calls
1
Stock
Class · 0.50
Tested by
no test coverage detected