How to use accumulate() with other function in Python

1 Answer

0 votes
from itertools import *

def f(a, b):         
    print("a =", a, "b =",b)
    print()
    return a + b     
    
print(list(accumulate('abcd', f)))



'''
run:

a = a b = b

a = ab b = c

a = abc b = d

['a', 'ab', 'abc', 'abcd']

'''

 



answered May 24, 2019 by avibootz
...