The reduce Function in Python


Performs a cumulative operation on a list.

Source Code

from functools import reduce

numbers = [1, 2, 3, 4]
result = reduce(lambda x, y: x + y, numbers)
print(result)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments