Created
January 8, 2014 12:10
-
-
Save draftcode/8315934 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import division, absolute_import, print_function, unicode_literals | |
def indicate_last(gen): | |
saved_e = None | |
prev_value = next(gen) | |
value = None | |
while True: | |
if saved_e is not None: | |
raise saved_e | |
try: | |
value = next(gen) | |
except StopIteration as e: | |
saved_e = e | |
yield prev_value, (saved_e is not None) | |
prev_value = value | |
value = None | |
for v, b in indicate_last(i for i in range(5)): | |
print(v, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment