Combining Iterables with FillValue

  • Share this:

Code introduction


This function combines iterables together. If the iterables are of unequal lengths, it fills the shorter ones with a fillvalue.


Technology Stack : zip_longest

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=0):
    zip_longest_generator = zip_longest(*args, fillvalue=fillvalue)
    while True:
        try:
            yield [next(iter(x)) for x in zip_longest_generator]
        except StopIteration:
            break                
              
Tags: