21.11.17 01:00, Terry Reedy пише:
On 11/20/2017 4:57 PM, Steven D'Aprano wrote:
Is there a reason for calling reversed() instead of reversing the order
of range in the first place?

range(len(iterables)-1, -1, -1)

Readability.  Accurately and automatically reversing ranges was one of the use cases motivating the addition of 'reversed'.  Ranges have a __reversed__ method which returns a iterator for a reversed range.

Agree. You also can write this as range(1, len(iterables))[::-1]. This is shorter and (I suppose) slightly faster. But reverse() can be better choice for a recipe, if it looks less confusing for beginners.

_______________________________________________
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