[Python-ideas] Rewriting the "roundrobin" recipe in the itertools documentation
tjreedy at udel.edu
Thu Nov 16 18:15:53 EST 2017
On 11/16/2017 2:42 PM, brent bejot wrote:
> I think the idea behind the original recipe is that when one of the
> inner lists has been iterated through, it is removed and never looked at
> again. Imagine the following scenario:
> L is a list which contains one million empty lists and also a list
> containing one million numbers
> Then the original recipe will iterate over two million(ish) items: each
> inner list must get visited and each item from the long inner list must
> get visited. However, your use of zip_longest must visit one trillion
> items, which will likely not finish in a reasonable amount of time.
> I'm not saying that this is likely to be the case, but this is probably
> why the original recipe is what it is. It would be great to see a
> recipe that is more pythonic but that maintains the efficiencies of the
> first recipy, but I could not come up with one.
The two assignments and while loop for 'pending' can be turned into a
for loop, as in my response (with correction).
Terry Jan Reedy
More information about the Python-ideas