Back
I have this code snippet which I can't understand:
>>> l = lambda: -4, 'c', 0>>> i = iter(l)>>> i<tuple_iterator object at 0x00700CD0>>>> next(i)<function <lambda> at 0x0070A4F8>>>> next(i)'c'>>> next(i)0>>> next(i)Traceback (most recent call last): File "<stdin>", line 1, in <module>StopIteration>>>
In your code l is tuple with 3 elements: A lambda that returns -4, a string ‘c’, and an integer 0.
The reason that it returns lambda object on first iteration and not -4 is because you need to call the lambda by using parentheses like:
next(i)()
31k questions
32.8k answers
501 comments
693 users