Python Forum

Full Version: itertools.zip_shortest() fo unequal iterators
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
itertools.zip_longest() exists but itertools.zip_shortest() does not. is there some other name to call to iterate each iterator (generator), in the given list, in parallel, stopping iteration when the shortest iterator (generator) runs out (length unknown in advance)?
That's what zip does.
that was the first one i looked for after i googled for this and it wasn't in there.
(Dec-25-2019, 07:11 PM)Skaperen Wrote: [ -> ]it wasn't in there.
it wasn't where? it's built-in function
and the docs are explicit:
Quote:The iterator stops when the shortest input iterable is exhausted.
i saw a web page that (maybe just poorly written) that suggested zip() and zip_longest() were both in itertools. but after post #2 i looked at builtins and saw it there. i had been assuming zip() was in itertools up until then. when i found it wasn't, i looked for zip_shortest and could not find that anywhere. then i looked for zip and it got me to itertools in another way. i must have looked for it w/o the ().

there needs to be a feature->name reference document. that would make searches a lot cleaner.
Long time ago I decided for myself to always first look into docs, not third-party sites.
there is index and also module-index
and also the search function normally works quite well (not in this case I admit)
both of those indexes require knowing the name of what you are looking for, first. what i mean is an index of the things to be done, such as a phrase of what you want to do. a keyword in context index would be even nicer.
How could an index find zip_shortest if the name doesn't exist? How would you formulate a query for this?
it would be an index branch describing the way iterators are handled and refer to what does exist ... builtin zip(). another branch with a slightly different description would refer to itertools.zip_longest().

and i just found a bug in the Firefox PDF reader's search that could miss some matches.
What you describe very much looks like sort of cookbook or tutorial. Whatever this document is, there is no way it could be exhaustive enough.
Pages: 1 2