Combining Iterables with Fillvalue

  • Share this:

Code introduction


The function combines multiple iterable objects into an iterator. If an iterable is shorter than the others, it is filled with a specified fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    # 将多个可迭代对象组合成一个迭代器,如果某个可迭代对象较短,则用fillvalue填充
    from itertools import zip_longest
    return zip_longest(*args, fillvalue=fillvalue)                
              
Tags: