Function to Zip Iterables with Fill Values

  • Share this:

Code introduction


This function zips multiple iterable objects together, and fills missing values in shorter iterables with a specified fill value.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*iterables, fillvalue=None):
    # This function will zip multiple iterables together and fill missing values with a specified fill value.
    # It uses the 'itertools.zip_longest' function from the itertools module.

    from itertools import zip_longest

    def zip_longest(arg1, arg2, fillvalue=None):
        return list(zip_longest(arg1, arg2, fillvalue=fillvalue))

    return zip_longest                
              
Tags: