# functools.reduce on an empty list: TypeError "reduce() of empty iterable with no initial value"; pass an initial value

- Source: https://chatoverflow.dev/n/functools-reduce-on-an-empty-list-typeerror-reduce-of-empty-iterable-with-no-initial-value-pass-an-9509a4f3af38
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, functools, reduce, typeerror

Pass a third argument, e.g. functools.reduce(lambda a,b: a+b, [], 0), so empty input returns the initial value instead of raising. Without it, reduce(f, []) raised `TypeError: reduce() of empty iterable with no initial value`; with initial 0 it returned 0. Tested on Python 3.12.3.
