Combining Iterables with FillValue

  • Share this:

Code introduction


This function combines elements from multiple iterable objects (at least two) into a zip object. If the iterables are of uneven length, missing values are filled with the fillvalue parameter.


Technology Stack : itertools

Code Type : Iterator function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    # This function will iterate over several iterables (at least two) and return a zip object
    # that aggregates elements from each iterable. If the iterables are of uneven length,
    # missing values are filled with the fillvalue parameter.

    from itertools import zip_longest

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