Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iterating over 2 iterators
#1
what was the name of that function that would iterate over 2 iterators and let you do:
   for x,y in iter2(xx,yy):
where xx and yy are 2 iterators of presumably the same length (else the iteration stops at the end of the shorter iterator).
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
https://docs.python.org/3/library/functions.html#zip Wrote:zip(*iterables)
Make an iterator that aggregates elements from each of the iterables.

Returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The iterator stops when the shortest input iterable is exhausted. With a single iterable argument, it returns an iterator of 1-tuples. With no arguments, it returns an empty iterator. ...
Reply
#3
thanks! that is the function i was looking for. i did remember it had an odd name but i was unable to come up with the right words to find it in the document or on google ("iterators" brings lots of noise).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  itertools.zip_shortest() fo unequal iterators Skaperen 10 6,580 Dec-27-2019, 12:17 AM
Last Post: Skaperen
  how to join 2 iterators Skaperen 2 2,610 Sep-11-2019, 07:19 PM
Last Post: Skaperen
  Iterators mp3909 3 2,981 Mar-16-2018, 09:42 PM
Last Post: nilamo
  2 iterators or generators Skaperen 1 28,439 Jan-04-2018, 07:41 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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