Last active
August 29, 2015 13:58
-
-
Save dracos/9933033 to your computer and use it in GitHub Desktop.
Iterators of prev/curr/next
This file contains hidden or 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
import itertools | |
def prevnext(it): | |
prev, curr, next = itertools.tee(it, 3) | |
prev = itertools.chain([None], prev) | |
next = itertools.islice(next, 1, None) | |
return itertools.izip_longest(prev, curr, next) | |
def prevnext(it): | |
it = iter(it) | |
prev = None | |
item = it.next() | |
for next in it: | |
yield (prev, item, next) | |
prev = item | |
item = next | |
yield (prev, item, None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My Pleasure to write you,
My name is Favor Williams,
My email address is
( [email protected])
Am interested to know
more about you,
Contact me for my
photo and other
important issue via,
[email protected]