Python - Itertools.zip_longest() Last Updated : 27 Feb, 2020 Comments Improve Suggest changes Like Article Like Report 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 Itertools.zip_longest() 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 fillvalue parameter. Syntax: zip_longest( iterable1, iterable2, fillval) Example 1: Python3 1== # Python code to demonstrate the working of # zip_longest() import itertools # using zip_longest() to combine two iterables. print ("The combined values of iterables is : ") print (*(itertools.zip_longest('GesoGes', 'ekfrek', fillvalue ='_' ))) Output: The combined values of iterables is : ('G', 'e') ('e', 'k') ('s', 'f') ('o', 'r') ('G', 'e') ('e', 'k') ('s', '_') Example 2: Python3 1== from itertools import zip_longest x =[1, 2, 3, 4, 5, 6, 7] y =[8, 9, 10] z = list(zip_longest(x, y)) print(z) Output: [(1, 8), (2, 9), (3, 10), (4, None), (5, None), (6, None), (7, None)] Comment More infoAdvertise with us Next Article Python - Itertools.zip_longest() techni621 Follow Improve Article Tags : Python Python-itertools Practice Tags : python Similar Reads Python Itertools 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. For example, let's suppose there are two lists and we wa 12 min read Python - Itertools.count() Python Itertools are a great way of creating complex iterators which helps in getting faster execution time and writing memory-efficient code. Itertools provide us with functions for creating infinite sequences and itertools.count() is one such function and it does exactly what it sounds like, it co 3 min read Python - Itertools.cycle() Iterator is defined as object types which contains values that can be accessed or iterated using a loop. There are different iterators that come built-in with Python such as lists, sets, etc. Itertools is the Python module that contains some inbuilt functions for generating sequences using iterators 3 min read Python - itertools.repeat() 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. Note: For more information, refer to Python Itertools re 2 min read Itertools.accumulate()-Python itertools.accumulate() is an iterator that takes two arguments, an iterable (target) and an optional function. The function is applied at each iteration to accumulate the result. By default, if no function is provided, it performs addition. If the input iterable is empty, the output will also be emp 3 min read Python - Itertools.chain() The itertools is a module in Python having a collection of functions that are used for handling iterators. They make iterating through the iterables like lists and strings very easily. One such itertools function is chain().Note: For more information, refer to Python Itertools chain() function It is 4 min read Python - Itertools.chain.from_iterable() 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. Note: For more information, refer to Python Itertools Th 2 min read Python - Itertools.compress() 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. Note: For more information, refer to Python Itertools Co 2 min read Python - Itertools.dropwhile() Itertools is a Python module that provide various functions that work on iterators to produce complex iterators. It makes the code faster, memory efficient and thus we see a better performance. This module is either used by themselves or in combination to form iterator algebra. Note: For more inform 1 min read Python - Itertools.filterfalse() In Python, Itertools is the inbuilt module that allows us to handle the iterators in an efficient way. They make iterating through the iterables like lists and strings very easily. One such itertools function is filterfalse(). Note: For more information, refer to Python Itertools filterfalse() funct 2 min read Like