Title: Python iterator: prev() like there is next()?
Tags: python
Question: Is there a way to do go backwards on an iterator. For example:
x = ['a','b','c'] # has __iter__
x_iter = iter(x)  # now has __next__
next(x_iter)
next(x_iter)
prev(x_iter) # what about adding a __prev__ ?
Comment: Are you just curios or do you have something where this would help you?

Comment: No, there isn't. Iterators don't generally have any memory.

Comment: The iterator protocol only has a `__next__` and nothing for previous. Of course, you could *implement* this on an object that also implements the Python iterator protocol, but that isn't going to be understood by other Python built-ins or have support built into the language, but nothing is stopping you



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:03/04/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python>', 'Title': 'Python iterator: prev() like there is next()?', 'ViewCount': 54, 'id': 60535278, 'user_AboutMe': None, 'user_AccountId': 16981299.0, 'user_DisplayName': 'samuelbrody1249', 'user_Reputation': 3763.0, 'user_Views': 534.0, 'user_id': 12283168.0}}