You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> next(iter([]))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
And if you do this in a list comprehension you get the same error
>>> x, y = [next(iter(z)) for z in ([], [])]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <listcomp>
StopIteration
But if you change list comprehension to a generator expression then the exception type is transformed!
>>> x, y = (next(iter(z)) for z in ([], []))
Traceback (most recent call last):
File "<stdin>", line 1, in <genexpr>
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: generator raised StopIteration
next
on an empty iter raisesStopIteration
And if you do this in a list comprehension you get the same error
But if you change list comprehension to a generator expression then the exception type is transformed!
This is new behavior as of Python 3.5 https://peps.python.org/pep-0479/
The text was updated successfully, but these errors were encountered: