Python Forum
itertools.zip_shortest() fo unequal iterators
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
itertools.zip_shortest() fo unequal iterators
#1
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)?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
That's what zip does.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
that was the first one i looked for after i googled for this and it wasn't in there.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
(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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#8
How could an index find zip_shortest if the name doesn't exist? How would you formulate a query for this?
Reply
#9
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#10
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  itertools and amazing speed Pedroski55 8 2,065 Nov-11-2022, 01:20 PM
Last Post: Gribouillis
  Why are two variables unequal as they point to the same value? fc5igm 4 2,732 Jun-08-2021, 02:41 PM
Last Post: fc5igm
  What happens to a <itertools.permutations object at 0x7fe3cc66af68> after it is read? Pedroski55 3 2,415 Nov-29-2020, 08:35 AM
Last Post: DeaD_EyE
  Making lists using itertools and eliminating duplicates. mike3891 2 2,249 Oct-26-2020, 05:39 PM
Last Post: bowlofred
  Python3 itertools.groupby printing the key august 1 2,096 Aug-17-2020, 05:46 AM
Last Post: bowlofred
  Generate Cartesian Products with Itertools Incrementally CoderMan 2 1,850 Jun-04-2020, 04:51 PM
Last Post: CoderMan
  how to join 2 iterators Skaperen 2 2,686 Sep-11-2019, 07:19 PM
Last Post: Skaperen
  can itertools compact a list removing all of some value? Skaperen 6 3,173 Sep-02-2019, 03:19 AM
Last Post: Skaperen
  Help with itertools jarrod0987 1 1,819 Jun-10-2019, 02:41 AM
Last Post: Larz60+
  iterating over 2 iterators Skaperen 2 2,258 Jun-07-2019, 11:37 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020