Here is how to loop through two lists at the same time in Python.


first_list = [1, 2, 3]
second_list = [10, 20, 30] 
for i, j in zip(first_list, second_list):
    print(i, j) 

Output

1 10
2 20
3 30


Explanation
We need to use the Python zip() function to stack the lists together. The zip function extract pairs of items from the two lists and create a list of tuples. Each tuple will have a pair of items.


Related HowTos
Do dictionary comprehension
Do list comprehension
Create a virtual environment
Create a new file
Merge two lists
Extract items from two different lists into one list
Check if a text file is empty
Randomly select an item from a list
Generate a random integer
Break a while loop
Create a pandas DataFrame from a dictionary
Create a pandas DataFrame from a list
Get the last item of a list
Delete a column from a pandas dataframe
Access a column of a pandas dataframe
Create a class
Make a webpage request
Get the first two characters of a string
Recommended Course

Learn Flask development and learn to build cool apps with our premium Python course on Udemy.


Mailing List

We will keep you Python-motivated if you subscribe below.