Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**List**: Materializes all elements in memory; indexable; reusable. **Generator**: Yields one element at a time; lazy; single-pass; memory O(1) for the sequence. **Why it matters**: Generators avoid loading huge datasets into memory; essential for streaming and large files....
Red Flag: Converting a generator to list for a single pass—wastes memory. Pro-Move: 'I use generators for ETL pipelines and file parsing; I chain them with itertools for composability and avoid materializing until necessary.'
This hard-level Python/Coding question appears frequently in data engineering interviews at companies like Altimetrik, Infosys. While less common, it tests deeper understanding that distinguishes strong candidates. Mastering the underlying concepts (python) will help you answer variations of this question confidently.
This is a senior-level question that tests architectural thinking. Lead with the high-level design, then drill into specifics. Discuss trade-offs explicitly - there is rarely one correct answer. Show awareness of scale, fault tolerance, and operational complexity.
List: Materializes all elements in memory; indexable; reusable. Generator: Yields one element at a time; lazy; single-pass; memory O(1) for the sequence. Why it matters: Generators avoid loading huge datasets into memory; essential for streaming and large files. Scalability trade-off: Generators can't be sliced or revisited without re-creation; lists support random access and multiple passes. Cost implication: Processing 10M rows as a list can OOM; as a generator it stays bounded. Example: [x for x in range(10)] vs (x for x in range(10)) or def gen(): yield x. Best practice: Use generators for large or unbounded data; use lists when you need multiple passes or indexing.
Red Flag: Converting a generator to list for a single pass—wastes memory. Pro-Move: 'I use generators for ETL pipelines and file parsing; I chain them with itertools for composability and avoid materializing until necessary.'
Some links below are affiliate links. If you buy through them we may earn a small commission at no extra cost to you — it helps keep DataEngPrep free.
According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 2 companies. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.