【问题标题】:How to increment a value in a dictionary in Python using a proportion?如何使用比例在 Python 中的字典中增加一个值?
【发布时间】:2021-11-10 07:22:05
【问题描述】:

我有以下参数:

policy_params["ub_2"]["rs"]

给出以下赋值:

 Out[62]: {1: 416, 2: 374, 3: 332, 4: 316, 5: 296, 6: 240}

我的问题是如何通过将上面的参数值 (rs) 增加 10% 来更改它?

policy_params_new = copy.deepcopy(policy_params)

for n in policy_params_new["ub_2"]["rs"]:
    policy_params_new["ub_2"]["rs"][n] += 

最后一行是我无法调整以增加 10% 的增量

【问题讨论】:

    标签: python dictionary increment proportions


    【解决方案1】:

    你可以试试除法:

    for n in policy_params_new["ub_2"]["rs"]:
        policy_params_new["ub_2"]["rs"][n] += policy_params_new["ub_2"]["rs"][n] / 10
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      • 2022-11-09
      相关资源
      最近更新 更多