I would like an elegant pythonic way to cycle through a list while having variables that have access to the current item and the next item during the iteration process. This is one method I know of that just gives me the current variable.
from itertools import cycle
stuff = ['a', 'b', 'c', 'd']
print(stuff)
for curr_item in cycle(stuff):
print("current:", curr_item)
Output:
['a', 'b', 'c', 'd']
current: a
current: b
current: c
current: d
current: a
current: b
current: c
...
Looking for something that kinda looks like:
from itertools import cycle
stuff = ['a', 'b', 'c', 'd']
print(stuff)
for curr_item, next_item in MAGIC(stuff):
print("current:", curr_item)
print("next:", next_item)
Desired output:
['a', 'b', 'c', 'd']
current: a
next: b
current: b
next: c
current: c
next: d
current: d
next: a
current: a
next: b
current: b
next: c
current: c
next: d
...