Python Function: Zip Longest with Fillvalue

  • Share this:

Code introduction


This function zips multiple iterables (like lists) together and fills in the missing values with a specified fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*iterables, fillvalue=None):
    # This function zips multiple iterables (like lists) and fills in missing values with fillvalue
    from itertools import zip_longest as zip_longest_from_itertools
    return list(zip_longest_from_itertools(*iterables, fillvalue=fillvalue))                
              
Tags: