Python‎ > ‎itertools‎ > ‎

itertools.accumulate()

http://www.adilwaseem.com/

Definition
Return series of accumulated sums or other binary function results.

Syntax
accumulate(iterable[, func]) --> accumulate object

Parameters
iterable & function

Example
The return is equal to:
 import itertools
set={"Python", "Lake", "learning", "Center"}
y=itertools.accumulate(set)
for value in y: print(value)

>>>
learning
learningLake
learningLakeCenter
learningLakeCenterPython
>>>

itertools.accumulate(set.difference)
The returns with accumulate of items of difference between sets.
from decimal import Decimal
import itertools
set1={Decimal(0.1).to_integral_value(),Decimal(1.9).to_integral_exact(),Decimal(1.5000001).to_integral(), Decimal(10).shift(2)}
set2={Decimal(1).scaleb(0), Decimal(1).remainder_near(2),Decimal(1.0000).normalize()}


x=set1.difference(set2)

y=itertools.accumulate(x)
for value in y:
print(value)

>>> 
1000
1000
1002
>>>

Comments