Zip Function with Filler for Different Length Iterables

  • Share this:

Code introduction


This function takes any number of iterable objects as input and returns an iterator that generates tuples, where each tuple contains elements from each input iterable. If the input iterables have different lengths, missing values from the shorter iterables are filled with empty strings.


Technology Stack : itertools

Code Type : Iterator function

Code Difficulty : Intermediate


                
                    
def zip(*iterables):
    zip_longest = itertools.zip_longest(*iterables, fillvalue='')
    return [tuple(item) for item in zip_longest]                
              
Tags: