Combining Iterables with Fillvalues

  • Share this:

Code introduction


The function is used to combine multiple iterable objects into a list. If the iterable objects have different lengths, fillvalue is used to fill up to the length of the shortest iterable.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    """
    Like zip(), but the output list is extended with fillvalues if the iterables are of uneven length.
    """
    from itertools import zip_longest
    return list(zip_longest(*args, fillvalue=fillvalue))                
              
Tags: