[Python-ideas] Adding a new function "zip_flat" to itertools (Re: Rewriting the "roundrobin" recipe in the itertools documentation)
storchaka at gmail.com
Tue Nov 21 01:16:50 EST 2017
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.
More information about the Python-ideas