降低
reduce 可能並不總是最有效的功能。對於某些型別,有相同的功能或方法:
-
sum()表示包含可新增元素(不是字串) 的序列的總和 :sum([1,2,3]) # = 6 -
str.join用於串聯串聯:''.join(['Hello', ',', ' World']) # = 'Hello, World' -
與
reduce相比,next和發電機可能是一個短路變體:# First falsy item: next((i for i in [100, [], 20, 0] if not i)) # = []