
Dec. 5, 2010
1:14 p.m.
Quoting from the http://docs.python.org/dev/py3k/whatsnew/3.2.html page: The itertools module has a new function, accumulate() modeled on APL’s scan operator and on Numpy’s accumulate function:>>> list(accumulate(8, 2, 50)) [8, 10, 60]
prob_dist = [0.1, 0.4, 0.2, 0.3] list(accumulate(prob_dist)) # cumulative probability distribution [0.1, 0.5, 0.7, 1.0] I'm not sure if this is a bug as I'm not sure if this is how the function actually behaves. Should the first function not take a list? For example:>>> list(accumulate([8, 2, 50])) [8, 10, 60]Notice the square brackets. I have not actually tested the function personally but it seems like something worth noting.