Combining Variable-Length Lists into Tuples

  • Share this:

Code introduction


Combine variable-length lists into tuples of equal length, filling in missing values with fillvalue.


Technology Stack : itertools

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_longest(*args, fillvalue=None):
    # 将可变数量的参数列表组合成一个个长度相等的元组,如果某个列表长度不足,则用fillvalue填充
    from itertools import zip_longest
    return list(zip_longest(*args, fillvalue=fillvalue))

# JSON representation                
              
Tags: