Python Function for Zipping Iterables with Fillvalue

  • Share this:

Code introduction


This function takes any number of iterable objects as arguments and returns a list of tuples. If the iterables have different lengths, the fillvalue is used to fill the shorter iterables.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=0):
    from itertools import zip_longest
    return list(zip_longest(*args, fillvalue=fillvalue))
                        
              
Tags: