Aggregating Iterables with Fill Value

  • Share this:

Code introduction


This function is used to aggregate multiple iterable objects into tuples. If the iterables are of unequal length, missing values are filled with a specified fill value.


Technology Stack : itertools

Code Type : Iterator function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    """
    This function takes any number of iterables and aggregates them into tuples.
    If the iterables are of unequal length, missing values are filled with a specified fillvalue.
    """
    from itertools import zip_longest

    return list(zip_longest(*args, fillvalue=fillvalue))                
              
Tags: