You can download this code by clicking the button below.
This code is now available for download.
This function combines multiple iterable objects into tuples, and if some iterable objects are of different lengths, it fills with fillvalue.
Technology Stack : itertools
Code Type : Function
Code Difficulty : Intermediate
def zip_longest(*args, fillvalue=()):
"""将可迭代对象组合为元组,如果其中某些对象长度不等,使用fillvalue填充。
Args:
*args: 可变数量的可迭代对象。
fillvalue: 当长度不等时填充的值。
Returns:
一个迭代器,产生元组,每个元组包含来自args的元素。
"""
from itertools import zip_longest
return zip_longest(*args, fillvalue=fillvalue)