0

What if we try to list() an infinite yield iterator?

2nd Nov 2016, 5:50 PM
Solstiche
3 odpowiedzi
+ 1
>>> def ooo(): ... yield 'ooo' ... >>> list(ooo()) ['ooo'] >>> list(ooo()) ['ooo'] ==================== >>> def ooo(): ... while True: ... yield 'ooo' ... >>> list(ooo()) ^CTraceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in ooo KeyboardInterrupt
3rd Nov 2016, 2:25 PM
Kirk Schafer
Kirk Schafer - avatar
0
error ?
3rd Nov 2016, 12:52 PM
Pierre Drt
- 1
The only error is going to be Python complaining about the size of your list
17th Feb 2017, 4:06 AM
Amaras A
Amaras A - avatar