On Wed, Apr 22, 2020 at 01:43:10AM -0300, Soni L. wrote:

> are there *any* solutions for getting partial results out of zip with 
> different-length iterators of unknown origin?

No. If you want to continue getting results even when one or more of 
the iterators is exhausted, `zip` is the wrong tool. Use `zip_longest`.


> >> 3. I feel like it makes intuitive sense for zip to return a partial 
> >> result somehow, especially now that StopIteration and return work 
> >together.
[...]

> it makes intuitive sense that there'd be some way to get the iterator 
> elements silently swallowed by zip against the wishes of the programmer. 

If you use zip, it is because you want zip's behaviour, which is 
explicitly documented as truncating on the shortest iterator. (Either 
that or you don't pay attention to the docs.)

You can't say "its against the wishes of the programmer". Nobody is 
forcing you to use zip except yourself. If you are hammering nails with 
a screwdriver, that's not the screwdriver's fault.

As I said, if you want to continue collecting values even after one or 
more iterators are exhausted, use zip_longest.


> there isn't. so we avoid it because it's useless for anything more 
> advanced than the "you've checked the lengths beforehand" use-case. 

I frequently use zip all the time with infinite iterators, or one 
infinite iterator like itertools.count() and one or more finite 
iterators, or more than one finite iterator, and I've never checked 
their lengths ahead of time.

Your statement that zip is "useless" unless you have checked the 
lengths first is simply nonsense.



-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/3JSY7UP2ZVISH7EA5MKEXQFYP7HOZYWO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to