Хотите (0, 1), (1, 2) или (0, 1), (2, 3)? Похоже, ваш вопрос говорит о том, что вы хотите один, и, кажется, о том, что вы хотите другой.
В любом случае, вот код для последнего:
#!/usr/local/cpython-3.8/bin/python3
import itertools
def test_data(n):
# Yes, there's a simpler way of doing this.
for i in range(n):
yield i
def two_up(iterable):
left_iterable, right_iterable = itertools.tee(iterable)
left_every_other = itertools.islice(left_iterable, 0, None, 2)
right_every_other = itertools.islice(right_iterable, 1, None, 2)
for tuple_ in zip(left_every_other, right_every_other):
yield tuple_
def main():
it = test_data(10)
for thing in two_up(it):
print(thing)
main()