Python zip_longest Function Implementation

  • Share this:

Code introduction


This function uses the zip_longest function from the itertools module to combine multiple iterable objects into an iterator. If the shortest input iterator runs out, it uses fillvalue to fill.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


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