Last active
December 13, 2019 11:23
-
-
Save egnha/fe5e2cff838b2e8f7f46a6d07584eb87 to your computer and use it in GitHub Desktop.
Lazy consecutive pairs
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
from itertools import islice, tee | |
def pairs(xs): | |
"""a, b, c, d, ... -> (a, b), (c, d), ...""" | |
fst, snd = (islice(_xs, start, None, 2) for start, _xs in enumerate(tee(xs))) | |
return zip(fst, snd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment