Combining Iterables with Fillvalue

  • Share this:

Code introduction


The function is used to combine multiple iterable objects into an iterator. If the shortest iterable is finished, fillvalue is used to fill the remaining values.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    zip_longest = itertools.zip_longest(*args, fillvalue=fillvalue)
    for tup in zip_longest:
        yield tup                
              
Tags: