Zip Longest with Fill Value

  • Share this:

Code introduction


This function zips together multiple iterable objects but allows None values for missing values in shorter iterables.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*iterables, fillvalue=None):
    """
    Zip together multiple iterables but allow None values for missing values.
    """
    # Use the zip_longest function from itertools package
    from itertools import zip_longest

    return list(zip_longest(*iterables, fillvalue=fillvalue))                
              
Tags: