Reputation: 63
For Lists and tuples I've been able to do the same thing to find NPV
cash_flow_list_of_lists = [[1, 200], [4, 500], [7, 1600]]
NPV=sum([cash_flow/(1.1**year) for year,cash_flow in
cash_flow_list_of_lists])
print("Present Value = " , (f"{NPV:9,.2f}"))
How do I do this with a dictionary list
cash_flow_dictionary = {1: 200, 4: 500, 7: 1600}
I tried NPV=sum([cash_flow_dictionary.values()]/(1.1**cash_flow_dictionary.keys()) in cash_flow_dictionary)
But I have no idea how to do this
Upvotes: 1
Views: 123
Reputation: 1586
The solution is provided below:
NPVDict = sum([cash_flow/(1.1**year) for year,cash_flow in
cash_flow_dictionary.items()]) # Note items function to iterate over dictionary
print("Present Value = " , (f"{NPVDict:9,.2f}"))
Let me know if it helps!!
Upvotes: 1