Skip to content

Instantly share code, notes, and snippets.

@blubberdiblub
Last active July 20, 2017 04:36
Show Gist options
  • Save blubberdiblub/4c786db200e909f30fcf to your computer and use it in GitHub Desktop.
Save blubberdiblub/4c786db200e909f30fcf to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import itertools
lines = ['one', 'two', 'three']
it, it_look_ahead = itertools.tee(lines)
next(it_look_ahead)
for line in it:
print("this line: %s" % (line,))
try:
next_line = next(it_look_ahead)
except StopIteration:
pass
else:
print("next line: %s" % (next_line,))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment