#Use the zip() Function

L1 = [1, 2, 3]
L2 = ["Python", "Java", "PHP"]

print(list(zip(L1, L2)))

The zip() function is used to combine two or more iterables into an iterator of tuples, where each tuple contains the elements in the corresponding indices of the iterables. All the elements in a given index are combined into one tuple. 

Syntax

zip(*iterables)

The function takes in an arbitrary number of iterables and returns an iterator of tuples.

For example, given two lists, the zip() function can be used to pair elements index-wise.

list1 = ['a','b','c']
list2 = [1,2,3]
iter_result = zip(list1, list2)
result = list(iter_result)
print(result)

The for loop equivalent of the above program is as shown below.

list1 = ['a','b','c']
list2 = [1,2,3]
result = []
for i, v in enumerate(list1):
    result.append((v, list2[i]))

print(result)

Example with three elements:

L1 = [1, 2, 3, 4]
L2 = [10, 20, 30, 40]
L3 = [100, 200, 300, 400]
zipped = zip(L1, L2, L3)
print(list(zipped))

If the given iterables are not of equal length, the zip function zips the elements up to the length of the smallest one. 

L1 = [1, 2, 3]
L2 = [10, 20, 30, 40]
L3 = [100, 200, 300, 400, 500]
zipped = zip(L1, L2, L3)
print(list(zipped))

More Examples:

countries = ('China', 'Rwanda', 'Canada', 'Philippines', 'Finland')
cities = ('Beijing', 'Kigali', 'Ottawa', 'Manilla', 'Helsinki')
zipped = zip(cities, countries)
print(list(zipped))

print('----------------------------------------')

a = [i for i in range(10)]
b = [i for i in range(10, 20)]
c = [i for i in range(20, 30)]
d = [i for i in range(30, 40)]
zipped = zip(a, b, c, d)
print(list(zipped))