Combining Iterables with FillValue Using zip_longest

  • Share this:

Code introduction


The function combines multiple iterable objects into an iterator, and if one iterable is exhausted, it fills the remaining positions with fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=0):
    """
    从a~z的顺序,使用了zip_longest函数。
    """
    from itertools import zip_longest
    return list(zip_longest(*args, fillvalue=fillvalue))                
              
Tags: