MCPcopy Create free account
hub / github.com/ActiveState/code / normDict

Function normDict

recipes/Python/278259_Dictionary_Tools/recipe-278259.py:92–100  ·  view source on GitHub ↗

Normalize the values of d by setting the largest value in d.values to normalizeTo. The return dict will have it's values spreading between 0~normalizeTo

(d, normalizeTo=1)

Source from the content-addressed store, hash-verified

90#========================================================================
91
92def normDict(d, normalizeTo=1):
93 ''' Normalize the values of d by setting the largest value in d.values
94 to normalizeTo. The return dict will have it's values spreading
95 between 0~normalizeTo'''
96 ks = d.keys()
97 vs = d.values()
98 vMax = max(vs)
99 vs= [ x/(vMax*1.0)*normalizeTo for x in vs]
100 return dict(zip(ks, vs))
101
102#========================================================================
103

Callers

nothing calls this directly

Calls 4

maxFunction · 0.50
dictClass · 0.50
keysMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected