Enhanced Zip Function for Variable Length Lists

  • Share this:

Code introduction


The `zip_longest` function is similar to `zip`, but it merges lists of different lengths, filling missing values with `fillvalue`.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=()):
    """
    Like zip(), but merges lists of different lengths, filling missing values with fillvalue.
    """
    from itertools import zip_longest as it_zip_longest
    return list(it_zip_longest(*args, fillvalue=fillvalue))                
              
Tags: