Python 3.x: Test if generator has elements remaining
This is a great question. I’ll try to show you how we can use Python’s introspective abilities and open source to get an answer. We can use the dis module to peek behind the curtain and see how the CPython interpreter implements a for loop over an iterator. >>> def for_loop(iterable): … for item in … Read more