小编Cri*_*son的帖子

如何划分字典值?

我有一个字典,由列表中的整数形式的键和值组成,例如,

input: {
    'example_key1': [358, 57, 18602, 18388],
    'example_key2': [415, 12, 4800, 2013],
    'example_key3': [450, 10, 4500, 4500],
}
Run Code Online (Sandbox Code Playgroud)

我希望将最后一个值与列表中每个键的倒数第二个值相除,将答案乘以 100,然后将答案输入到类似的字典中,ndigit = 1 分。

output: {
    'example_key1': [98.8],   # [round((((18388 / 18602)) * 100), 1)]
    'example_key2': [41.9],   # [round((((2103 / 4800)) * 100), 1)]
    'example_key3': [100.0],  # [round((((4500 / 4500)) * 100), 1)]
}
Run Code Online (Sandbox Code Playgroud)

python dictionary

1
推荐指数
1
解决办法
98
查看次数

标签 统计

dictionary ×1

python ×1