On 4/25/2019 7:12 PM, Greg Ewing wrote:
Steven D'Aprano wrote:
I too often forget that reverse() returns an iterator,

I presume you mean reversed().  list.reverse() is a list

That seems like a mistake. Shouldn't it return a view?

RL = reversed(somelist) is already partly view-like. The nth next call returns the nth item at the time of the next call, rather than at the time of the reversed call. However, the number of items produced by next calls is the length of the list at the time of the reversed call. The first next(RL) is the current somelist[captured_length].

>>> somelist = [1,2,3]
>>> RL = reversed(somelist)
>>> somelist[-1] = None
>>> somelist.append(4)
>>> list(RL)
[None, 2, 1]



--
Terry Jan Reedy

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to