Say I have these three lists:
a = [1, 2, 3, 4]
b = [5, 6, 7, 8, 9]
c = [10, 11, 12]
Is there a builtin function such that:
somezip(a, b) == [(1, 5), (2, 6), (3, 7), (4, 8)]
somezip(a, c) == [(1, 10), (2, 11), (3, 12), (4, None)]
Behaving somewhere between zip and zip_longest?
No there isn’t, but you can easily combine the functionality of takewhile and izip_longest to achieve what you want
(In case the first-iterator may have items which evaluates to False, you can replace the itemgetter with a lambda expression – refer @ovgolovin’s comment)
Examples