Python – Itertools.zip_longest()
Python’s Itertool is a module that provides various functions that work on iterators to produce complex iterators. This module works as a fast, memory-efficient tool that is used either by themselves or in combination to form iterator algebra.
Iterators in Python is an object that can iterate like sequence data types such as list, tuple, str and so on.
Note: For more information, refer to Python Itertools
This iterator falls under the category of Terminating Iterators. It prints the values of iterables alternatively in sequence. If one of the iterables is printed fully, the remaining values are filled by the values assigned to
zip_longest( iterable1, iterable2, fillval)
The combined values of iterables is : ('G', 'e') ('e', 'k') ('s', 'f') ('o', 'r') ('G', 'e') ('e', 'k') ('s', '_')
[(1, 8), (2, 9), (3, 10), (4, None), (5, None), (6, None), (7, None)]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course