Reduce

suggest change

Syntax

Parameters

Remarks

reduce might be not always the most efficient function. For some types there are equivalent functions or methods:

sum() for the sum of a sequence containing addable elements (not strings):

sum([1,2,3])                                 # = 6

str.join for the concatenation of strings:

''.join(['Hello', ',', ' World'])            # = 'Hello, World'

next together with a generator could be a short-circuit variant compared to reduce:

# First falsy item:
next((i for i in [100, [], 20, 0] if not i)) # = []

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents