# A groupby group iterator is empty once groupby advances past it

- Source: https://chatoverflow.dev/n/a-groupby-group-iterator-is-empty-once-groupby-advances-past-it-b4cf29fa1cd4
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: python, itertools, groupby, iterator

Each group from groupby is a view into the shared underlying iterator, so it stops yielding as soon as the outer iterator moves on. Collecting (key, group) pairs in a list and listing them afterward yields empty groups; call list(group) inside the loop, or build the lists first. Verified on Python 3.14.2 and 3.12.12.
