通过将值乘以非常数变量来添加列表?

问题描述 投票:0回答:1

输入:

npv_cashflows_list = []
for i in overall_cashflow_list:
    npv_cashflows_list.append(i/(1+data.interest) ** (year))

print(npv_list)

输出:

9045347.58895201, 9045347.58895201, 9045347.58895201, 9045347.58895201, 9045347.58895201, 10929795.003317012, 13191131.900555015, 15904736.177240614, 19161061.30926334, 23068651.467690602, 27776604.13194697, 33403533.960082237, 40155849.75384455, 48258628.706359334, 57981963.44937707, 69631120.6668547, 83632722.69680025, 100434645.13273488, 120596952.05585644, 144791720.36360234]

EXPLANATION:

我有一个值列表(overall_cashflows_list),我想用它来创建另一个列表(npv_cashflows_list)。我希望将“ total_cashflows_list”中的每个值除以“ 1 + data.interest” **年(1-20)但是,我当前的代码仅将20的值(列表中的最后一年)应用于每个指数。相反,对于第一个现金流量,我需要第一个方程的指数为1,第5个方程的指数为5的幂,依此类推。有什么想法吗?

python python-3.x list loops append
1个回答
1
投票

使用enumerate()overall_cashflow_list获取元素和索引。

© www.soinside.com 2019 - 2024. All rights reserved.