On Sat, Jan 09, 2021 at 11:22:35AM +1300, Greg Ewing wrote:

> Also it's hard to see how it could be made to work, because the
> argument to reversed() necessarily has to be a sequence, not an
> iterator.

No, it just needs a `__reversed__` dunder. It doesn't even need to be an 
iterable or sequence at all!

>>> class X:
...     def __reversed__(self):
...             return iter("Bet you didn't see this coming.".split())
... 
>>> list(reversed(X()))
['Bet', 'you', "didn't", 'see', 'this', 'coming.']



-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/I5UEXK5A4A2CMERTKBK63KLHUITF7GHS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to