Define a function myreduce(seq, func, initial) that reduces the elements of seq using the binary function func, starting with the value initial.

def myreduce(func, seq, initial):
    """Aggregate elements of seq using func starting with initial.

    >>> myaggregate(lambda x, y: x + y, [1, 2, 3], 0)
    6
    >>> myaggregate(lambda x, y: x * y, [1, 2, 3, 4], 1)
    24
    >>> myaggregate(lambda x, y: x + y, [], 10)
    10
    >>> myaggregate(lambda x, y: x - y, [2, 3, 4], 20)
    11
    """
Library
from functools import reduce
numbers = [1, 2, 3, 4]
total = reduce(lambda x, y: x + y, numbers, 0)
print(total)  # Output: 10

Updated: