python next item in list

Solutions on MaxInterview for python next item in list by the best coders in the world

showing results for - "python next item in list"
Lili-Rose
07 Nov 2018
1# credit to Stack Overflow user in the source link
2
3from itertools import cycle
4
5li = [0, 1, 2, 3]
6
7running = True
8licycle = cycle(li)
9
10nextelem = next(licycle)
11
12while running:
13    thiselem, nextelem = nextelem, next(licycle)