You can download this code by clicking the button below.
This code is now available for download.
This function takes multiple iterable objects and returns an iterator that aggregates elements from each of the iterables. If the iterables are of uneven length, missing values are filled with fillvalue.
Technology Stack : array, bisect, cmath, collections, concurrent.futures, contextlib, csv, functools, html, io, itertools, json, math, operator, random, re, shutil, statistics, subprocess, sys, threading, time, traceback, uuid
Code Type : Function
Code Difficulty : Intermediate
import array
import bisect
import cmath
import collections
import concurrent.futures
import contextlib
import csv
import functools
import html
import io
import itertools
import json
import math
import operator
import random
import re
import shutil
import statistics
import subprocess
import sys
import threading
import time
import traceback
import uuid
def zip_longest(*iterables, fillvalue=None):
# This function takes multiple iterables and returns an iterator that aggregates elements from each of the iterables.
# If the iterables are of uneven length, missing values are filled with fillvalue.
iterators = [iter(i) for i in iterables]
while True:
result = []
for it in iterators:
try:
result.append(next(it))
except StopIteration:
iterators.remove(it)
if not iterators:
return
result.append(fillvalue)
yield tuple(result)