The correct way is to use the zip function.
Alternatively, we can use lists and the built-in enumerate function to achieve the same result.
>>> L1 = [1,2,3,4] >>> L2 = [5,6,7] >>> [(value, L2[i]) for i, value in enumerate(L1) if i < len(L2)] [(1, 5), (2, 6), (3, 7)] >>>
The disadvantage of the above example is that we do not always iterate over a list with a minimum length.
Nick dandoulakis
source share