[Python-ideas] Adding a new function "zip_flat" to itertools (Re: Rewriting the "roundrobin" recipe in the itertools documentation)
Steven D'Aprano
steve at pearwood.info
Mon Nov 20 16:57:57 EST 2017
On Mon, Nov 20, 2017 at 12:15:50PM -0500, Terry Reedy wrote:
> >Your version truncates the results to A B C instead of A B C D E as the
> >itertools recipe gives.
>
> This is due to an off-by-1 error which I corrected 3 hours later in a
> follow-up post, repeated below.
Ah, I missed that, thanks.
> > def roundrobin(*iterables):
> > "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
> > nexts = cycle(iter(it).__next__ for it in iterables)
> > for reduced_len in reversed(range(1, len(iterables))):
>
> Make that 0 rather than 1 for start value.
Is there a reason for calling reversed() instead of reversing the order
of range in the first place?
range(len(iterables)-1, -1, -1)
--
Steve
More information about the Python-ideas
mailing list