Created
February 2, 2012 22:03
-
-
Save signed0/1726072 to your computer and use it in GitHub Desktop.
Pairs Iterator
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
def pairs(iterable): | |
'''Generate pairs of items in iterable''' | |
i = iter(iterable) | |
prev = i.next() | |
for j in i: | |
yield prev, j | |
prev = j |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment