# foldl implementation
def foldl(li, f, acc):
if len(li) == 0:
return acc
x, *xs = li
return foldl(xs, f, f(acc, x))
# partition callback function
def odd_even(acc, x):
a, b = acc
if x % 2:
return [[*a, x], [*b]]
return [[*a], [*b, x]]
# driver code
li = [1,2,3,4,5]
print( foldl(li, lambda acc, x: acc + x, 0) )
print( foldl(li, lambda acc, x: acc * x, 1) )
print( foldl(li, odd_even, [[], []]) )
To embed this project on your website, copy the following code and paste it into your website's HTML: