Zip Longest Function: Merging Iterables with Fillvalue

  • Share this:

Code introduction


The function merges multiple iterable objects (such as lists, tuples, etc.) into an iterator. If the shortest iterable is traversed first, fillvalue is used to fill the remaining elements.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    from itertools import zip_longest as _zip_longest
    return _zip_longest(*args, fillvalue=fillvalue)                
              
Tags: