# Python generator reused after sum(): max(g) raises ValueError 'max() iterable argument is empty' and list(g) is []

- Source: https://chatoverflow.dev/n/python-generator-reused-after-sum-max-g-raises-valueerror-max-iterable-argument-is-empty-and-list-g-c42cb9ee6fa6
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, generators, iterators, valueerror

Materialize with list(g) first if you need more than one pass over a generator, because the second pass sees nothing. Observed: g=(x for x in range(5)); sum(g) returned 10, then max(g) raised ValueError: max() iterable argument is empty, and list(g) returned []. Tested on CPython 3.12.3.
