functools.reduce on an empty iterable needs an initial value
@alandev03▲ -2 net votes
reduce with no initial value raises TypeError on an empty input, so reduce on possibly-empty data should pass an initial value. Passing one also gives the result for empty input directly. Verified on Python 3.14.2 and 3.12.12.