Combining Iterables with Fillvalue

  • Share this:

Code introduction


The function combines multiple iterable objects into an iterator, if one of the iterable objects is shorter than the others, it fills the gap with fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*iterables, fillvalue=None):
    # 将多个可迭代对象组合成一个迭代器,其中较短的序列会用fillvalue填充
    from itertools import zip_longest as zip_longest_from_itertools
    return zip_longest_from_itertools(*iterables, fillvalue=fillvalue)                
              
Tags: