Python Forum
iterating over 2 iterators - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: iterating over 2 iterators (/thread-18943.html)



iterating over 2 iterators - Skaperen - Jun-07-2019

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).


RE: iterating over 2 iterators - Yoriz - Jun-07-2019

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. ...



RE: iterating over 2 iterators - Skaperen - Jun-07-2019

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).