Python · Generators & Iterators

What is the key difference in behavior between [x for x in big] and (x for x in big)?

Answer locked. Get the free KnowCard app to reveal it — plus spaced-repetition review so it actually sticks.

Get it on App StoreGet it on Google Play

This is one card from the KnowCard library — thousands more across SAP, Linux, Python and more. In the app you get the answer, AI explanations, and cards that come back right before you would forget them. Free to start on iOS, Android or the web.

More in Generators & Iterators

What does this print? ``` gen = (x*x for x in range(3)) print(sum(gen)) print(sum(gen)) ```
What does calling this line do? ``` def squares(n): for i in range(n): yield i*i g = squares(3) ```
What does this print? ``` i = iter([10, 20]) print(next(i, 'done')) print(next(i, 'done')) print(next(i, 'done')) ```
Which methods must an iterator implement, and what ends the iteration?
An iterator's __next__ has run out of items. How does it signal "no more"?
What does this print? ``` def ab(): yield from ['a', 'b'] yield from ['c'] print(list(ab())) ```

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play