Divide dictionary value(s) by integer value

时间:2015-09-14 15:22:31

标签: python python-3.x dictionary

I have a dictionary with only one entry (key names are varying and I don't know them) and want to divide the value by another integer value.

Since dict.values() only delivers dict views which were not suitable for a division, my workaround was to convert the dictionary value into a list and getting the element by its index:

in_max = {'b_el': 100000}
soc_max = 700000
c_rate_in = [in_max[k] for k in in_max][0] / soc_max

print(c_rate_in)
0.14285714285714285

But this solution seems to be a bit heavy-handed to me and also does not look very nice.

Is there a smarter way to get the same result?

0 个答案:

没有答案