itertools 'previous' (opposite of next) python
You can use deque
from collections
module and rotate
method,
for example:
from collections import deque
alist=['a','b','c']
d=deque(alist)
current = d[0]
print(current) # 'a'
d.rotate(1) # rotate one step to the right
current = d[0]
print(current) # 'c'
d.rotate(-1) # rotate one step to the left
current = d[0]
print(current) # 'a' again
No, there isn't.
Because of the way Python's iteration protocol works, it would be impossible to implement previous
without keeping the entire history of the generated values. Python doesn't do this, and given the memory requirements you probably wouldn't want it to.