1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
>>> # given a list of (qty, price) tuples:
>>> purchases = [(1003.20, 13.25), (15.86, 13.87), (65.31, 13.78), (16.02, 13.73), (15.88, 13.85), (73.41, 13.7
6), (74.74, 13.38), (74.074, 13.5), (16.141, 13.63), (15.99, 13.76), (16.09,13.67)]

>>> # figure out the total quantity of shares:
>>> total_qty_shares = sum(map(lambda x : x[0], purchases))
1386.7150000000004

>>> # figure out the average cost per share
>>> (sum(map(lambda x : x[0] * x[1], purchases))) / total_qty_shares
13.357004813534141