0
What if we try to list() an infinite yield iterator?
3 Antworten
+ 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
0
error ?
- 1
The only error is going to be Python complaining about the size of your list