Python Zip Longest Wrapper

  • Share this:

Code introduction


Wraps the Python built-in library itertools' zip_longest function, which is used to combine elements of several iterables. For shorter iterables, fillvalue can be used as a fill-in.


Technology Stack : itertools

Code Type : Built-in function encapsulation

Code Difficulty : Intermediate


                
                    
def zip_longest(*iterables, fillvalue=None):
    # zip_longest function combines the elements of several iterables, allowing fillvalues for shorter iterables
    from itertools import zip_longest as it_zip_longest

    def wrapper(*args, **kwargs):
        return it_zip_longest(*args, fillvalue=fillvalue)

    return wrapper                
              
Tags: