5 ms·
> # pcost.py > total_cost = 0.0 > with open('../../Data/portfolio.dat', 'r') as f: > for line in f: > fields = line.split() > nshares = in
by heywhatupboys 3y ago
> # pcost.py
> total_cost = 0.0
> with open('../../Data/portfolio.dat', 'r') as f:
> for line in f:
> fields = line.split()
> nshares = int(fields[1])
> price = float(fields[2])
> total_cost = total_cost + nshares * price
> print(total_cost)
yikes what a terrible reference implementation! Least they could do is reduce([...], +) as a two-liner
- w0m 3y agohttps://www.artima.com/weblogs/viewpost.jsp?thread=98196 https://www.artima.com/weblogs/viewpost.jsp?thread=98196 map/reduce (for better or worse) get a bad rap. Some blog or training I took when first starting up with the language told me 'map/reduce Bad' and I have generally avoided ever since.