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

Function normListSumTo

recipes/Python/278257_List_Tools/recipe-278257.py:17–21  ·  view source on GitHub ↗

normalize values of a list to make it sum = sumTo

(L, sumTo=1)

Source from the content-addressed store, hash-verified

15
16#========================================================================
17def normListSumTo(L, sumTo=1):
18 '''normalize values of a list to make it sum = sumTo'''
19
20 sum = reduce(lambda x,y:x+y, L)
21 return [ x/(sum*1.0)*sumTo for x in L]
22
23#========================================================================
24def accumList(L, normalizeTo=None):

Callers 2

accumListFunction · 0.70
accumDictFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected