Extended Zip Function for Longest Sequence

  • Share this:

Code introduction


This function is similar to the built-in `zip` function, but it keeps the longest input sequence, filling shorter sequences with `fillvalue`.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=()):
    """
    Similar to the built-in `zip` function, but will keep the longest input sequence.
    """
    from itertools import zip_longest
    return zip_longest(*args, fillvalue=fillvalue)                
              
Tags: