<div dir="ltr">(Regarding the stackoverflow link, he does have a version that includes the trivial fix to apply iter() to args, at the bottom of the post.)<div><br></div><div>I think that the variety of solutions with a variety of merits is indicative that it would be useful to have a "zip_flat" in the itertools module, but I guess support for that isn't very strong here. I see that Terry opened a bug to clean up the current recipe in the docs, which is better than nothing, but I think it's the absolute bare minimum improvement.</div><div><br></div><div>I'm prepared to drop the subject unless there's further discussion in favor of it.</div><div><br></div><div>Thanks again to all for the replies.</div><div><br></div><div>Bill</div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 20, 2017 at 10:08 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Bill,<br>
<br>
I don't have time to go through your email in detail and respond to<br>
every point you raise, but I'd like to respond to one point you made.<br>
<span class=""><br>
On Mon, Nov 20, 2017 at 02:03:13AM -0600, bunslow wrote:<br>
<br>
> I also found this answer:<br>
><br>
> <a href="https://stackoverflow.com/questions/243865/how-do-i-merge-two-python-iterators/40498526#40498526" rel="noreferrer" target="_blank">https://stackoverflow.com/<wbr>questions/243865/how-do-i-<wbr>merge-two-python-iterators/<wbr>40498526#40498526</a><br>
><br>
> which proposes a solution that is both more correct and efficient than the<br>
> zip_longest-with-sentinels, and also noticeably more readable than either<br>
> the original doc recipe or even Terry's cleaned up replacement of it.<br>
<br>
</span>Please don't make claims about correctness and efficiency without<br>
testing the code first. The second suggestion given there, using deque,<br>
is *not* correct as provided, as it fails to work with iterables. It<br>
requires the caller to pass only iterators, unlike the existing<br>
roundrobin recipe which accepts any iterable.<br><br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Nor is it more efficient, at least on my machine -- in fact the<br>
opposite, it is the worst performing of the four recipes I've tried:<br>
<br>
- the current recipe from the itertools docs;<br>
- your re-write, using zip_longest;<br>
- Terry's version;<br>
- and the one from stackoverflow.<br>
<br>
I've attached my test code, in case you want to play around with it.<br>
Apologies in advance for any bugs in the test code (its 2 in the<br>
morning here and I've had a long day).<br>
<br>
According to my testing, on my computer using Python 3.5, Terry's code<br>
is by far the fastest in all three separate test cases, but that<br>
probably shouldn't count since it's buggy (it truncates the results and<br>
bails out early under some circumstances). Out of the implementations<br>
that don't truncate, the existing recipe is by far the fastest.<br>
<br>
Terry, if you're reading this, try:<br>
<br>
list(roundrobin('A', 'B', 'CDE'))<br>
<br>
Your version truncates the results to A B C instead of A B C D E as the<br>
itertools recipe gives.<br>
<br>
But I digress... the point is, if you're going to make claims about the<br>
correctness and efficiency of code, you really ought to actually check<br>
the correctness and efficiency first.<br>
<br>
I may or may not get around to responding to some of your other points<br>
over the next few days.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
Steve<br>
</font></span><br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
<br></blockquote></div><br></div></div></div>