Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
A list comprehension builds the whole list in memory immediately; a generator expression produces items lazily one at a time, which saves memory but can be consumed only once.
[x * 2 for x in data] evaluates everything right away and returns a list you can index, measure and iterate many times. (x * 2 for x in data) returns a generator that computes each value only when asked, so it handles very large or infinite inputs with constant memory. Generators fit pipelines and functions that consume an iterable once, such as sum(x * x for x in nums). Lists fit cases that need random access, len(), or repeated iteration. Readability matters too: deeply nested comprehensions are often clearer as regular loops.