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

Function accumList

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

L= [1, 2, 3, 4, 5]: accumList(L)=> [1, 3, 6, 10, 15] L= [0.25, 0.25, 0.25, 0.25]: accumList(L)=> [0.25, 0.50, 0.75, 1.00] normalizeTo: set the last number of the returned list to this value

(L, normalizeTo=None)

Source from the content-addressed store, hash-verified

22
23#========================================================================
24def accumList(L, normalizeTo=None):
25 ''' L= [1, 2, 3, 4, 5]: accumList(L)=> [1, 3, 6, 10, 15]
26 L= [0.25, 0.25, 0.25, 0.25]: accumList(L)=> [0.25, 0.50, 0.75, 1.00]
27 normalizeTo: set the last number of the returned list to this value
28 '''
29
30 if normalizeTo: LL = normListSumTo(L, sumTo=normalizeTo)
31 else: LL = L[:]
32
33 r = range(1, len(LL))
34 newList=[LL[0]]
35 for i in r:
36 newList.append( newList[-1]+ LL[i] )
37 return newList
38
39#========================================================================
40def findIndex(sortedList, x, indexBuffer=0):

Callers 2

randomPickListFunction · 0.70
randomPickDictFunction · 0.50

Calls 3

rangeFunction · 0.85
normListSumToFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected