Zip Longest Function Overview

  • Share this:

Code introduction


This function takes multiple iterable objects and aggregates them into tuples. If the iterables are of uneven length, missing values are filled with the fillvalue.


Technology Stack : itertools

Code Type : Iterator processing

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=0):
    # This function takes several iterables and aggregates them into tuples. 
    # If the iterables are of uneven length, missing values are filled with the fillvalue.

    from itertools import zip_longest

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