Combining Iterables with Fillvalue

  • Share this:

Code introduction


This function combines multiple iterable objects. If the lengths of the iterables are different, it fills the shorter ones with the fillvalue.


Technology Stack : zip_longest

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    zip_longest = zip_longest(*args, fillvalue=fillvalue)
    for i in zip_longest:
        if fillvalue in i:
            yield i
        else:
            yield list(i)                
              
Tags: