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)
| 22 | |
| 23 | #======================================================================== |
| 24 | def 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 | #======================================================================== |
| 40 | def findIndex(sortedList, x, indexBuffer=0): |
no test coverage detected