You may find multiplying is still faster than dividing
d2 = {k: v * 0.5 for k, v in d.items()}
For inplace version
d.update((k, v * 0.5) for k,v in d.items())
In general
def f(x)
"""Divide the parameter by 2"""
return x / 2.0
d2 = {k: f(v) for k, v in d.items()}
source
share