Post

@PythonPr range(3) gives 0, 1, 2.
i*i makes 0, 1, 4.
First list(x) -> [0, 1, 4]
Generator is now empty.
Second list(x) -> []
English

@PythonPr B. This is a generator and can return the values 0, 1, and 4. The 1st print statement consumes these values and there is nothing left in x for the 2nd print statement to print. So, [0,1,4] []
English

@PythonPr B) [0, 1, 4] and [].
Here's the logic;
Generator Expression: The line x = (i*i for i in range(3)) creates a generator object. Unlike lists, generators are iterators that yield values on the fly and do not store them in memory.
First print: When list(x) is called the
English

@PythonPr At first glance, it looks like a tuple comprehension, but there's no such thing in my experience. The value of x would be a generator (or iterator - as a noob I cannot differentiate). A generator can only be materialized once afaik. The answer is B, I think.
English



















