from typing import List, Iterable, Any
def super_zip(*args: Iterable) -> List[tuple]:
count = len(args)
lengths = {i: len(v) for i, v in enumerate(args)}
max_values_index = max(lengths, key=lengths.get)
def extract(chunk_index: int, value_index: int) -> Any:
try:
return args[chunk_index][value_index]
except IndexError:
return None
return [
tuple(extract(ci, vi) for ci in range(count))
for vi in range(lengths[max_values_index])
]
super_zip('abc', [1, 2, 3], ('Z', 'X', 'C'))
# [('a', 1, 'Z'), ('b', 2, 'X'), ('c', 3, 'C')]
super_zip('abc', [1, 2, 3, 4], ('Z', 'X'))
# [('a', 1, 'Z'), ('b', 2, 'X'), ('c', 3, None), (None, 4, None)]
super_zip('abc')
# [('a',), ('b',), ('c',)]