Is there an idiomatic way of taking two elements from an iterable like from a shift register? I have seen this, but it's another case. For the following example:
for i, j in something_i_need(range(5)):
print("%d %d" % (i, j))
I expect the output:
0 1
1 2
2 3
3 4
I know I can perform this using:
def shift_register(it):
it = iter(it)
x = next(it)
for y in it:
yield x, y
x = y
But i started wondering whether the python standard library contains something for this common use case so I don't have to reinvent the wheel.
In my usecase the iterator is infinite.