You can download this code by clicking the button below.
This code is now available for download.
This function combines multiple input sequences into a single sequence of tuples. If the sequences are of uneven length, missing values are filled with fillvalue.
Technology Stack : itertools
Code Type : Function
Code Difficulty : Intermediate
def zip_longest(*args, fillvalue=()):
"""Zip the input sequences together into a single sequence of tuples.
If the sequences are of uneven length, missing values are filled with fillvalue.
Args:
*args: An arbitrary number of sequences.
fillvalue: The value to use for missing values.
Returns:
A list of tuples containing values from the input sequences.
"""
from itertools import zip_longest as zip_longest_imp
return list(zip_longest_imp(*args, fillvalue=fillvalue))