You can download this code by clicking the button below.
This code is now available for download.
This function uses the itertools.zip_longest function to combine multiple iterable objects whose lengths may differ. If data in a certain iterable is exhausted, fillvalue is used to fill the remaining positions.
Technology Stack : itertools
Code Type : Function
Code Difficulty : Intermediate
def zip_longest(*iterables, fillvalue=None):
zip_longest(*iterables, fillvalue=None)
"""
使用 itertools 库中的 zip_longest 函数来合并多个可迭代对象,如果某些可迭代对象长度不同,则用 fillvalue 填充。
"""
import itertools
# 使用 itertools.zip_longest 来合并多个可迭代对象
for combination in itertools.zip_longest(*iterables, fillvalue=fillvalue):
print(combination)