Skip to content

Instantly share code, notes, and snippets.

@dracos
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dracos/9933033 to your computer and use it in GitHub Desktop.
Save dracos/9933033 to your computer and use it in GitHub Desktop.
Iterators of prev/curr/next
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)
@Favorwilliams
Copy link

My Pleasure to write you,
My name is Favor Williams,
My email address is
( Favor24@live.com)
Am interested to know
more about you,
Contact me for my
photo and other
important issue via,

Favor24@live.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment