Skip to content

Instantly share code, notes, and snippets.

@vegarsti
Last active February 27, 2018 10:23
Show Gist options
  • Save vegarsti/042da1bbb6b52f66f302e11fd6053559 to your computer and use it in GitHub Desktop.
Save vegarsti/042da1bbb6b52f66f302e11fd6053559 to your computer and use it in GitHub Desktop.
  • tee from itertools is cool! link
from itertools import tee
i, j = tee(data)
next(j)
for first, second in zip(i, j):
'from itertools import tee',
 'a = range(10)',
 'next(a)',
 'a = iter(range(10))',
 'next(a)',
 'a',
 'b = tee(a)',
 'tee',
 'c = next(tee)',
 'e, f = b',
 'e',
 'next(e)',
 'next(f)',
 'next(f)',
 'next(f)',
 'next(f)',
 'next(e)',
 6: 0,
 7: <range_iterator at 0x113f05f60>,
 9: <function itertools.tee>,
 12: <itertools._tee at 0x1150f6e08>,
 13: 1,
 14: 1,
 15: 2,
 16: 3,
 17: 4,
 18: 2,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment