Combining Iterables with Fillvalue Using zip_longest

  • Share this:

Code introduction


The zip_longest function from the itertools module combines multiple iterable objects. If one of the iterable objects is shorter than the others, it fills the remaining positions with a fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*iterables, fillvalue=None):
    # zip_longest function from itertools module which fills missing values with fillvalue
    from itertools import zip_longest
    return list(zip_longest(*iterables, fillvalue=fillvalue))                
              
Tags: