Combining Iterables with Fillvalue

  • Share this:

Code introduction


Combines multiple iterable objects into a single iterator. If one of the iterables is exhausted, the remaining positions are filled with a specified fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*iterables, fillvalue=None):
    # 将可迭代对象组合成一个新的迭代器,如果最短的迭代器耗尽,则用fillvalue填充
    from itertools import zip_longest
    return list(zip_longest(*iterables, fillvalue=fillvalue))                
              
Tags: