Combining Iterables with zip_longest

  • Share this:

Code introduction


The function uses the zip_longest function from the itertools module to combine multiple iterable objects into an iterator. If the shortest iterable object is exhausted, fillvalue is used to fill the remaining iterable objects.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=()):
    from itertools import zip_longest
    return list(zip_longest(*args, fillvalue=fillvalue))

# JSON response                
              
Tags: