
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to loop through multiple lists using Python?
The most straightforward way seems to use an external iterator to keep track. Note that this answer considers that you're looping on same sized lists.
example
a = [10, 12, 14, 16, 18] b = [10, 8, 6, 4, 2] for i in range(len(a)): print(a[i] + b[i])
Output
This will give the output −
20 20 20 20 20
Example
You can also use the zip method that stops when the shorter of a or b stops.
a = [10, 12, 14, 16, 18] b = [10, 8, 6] for (A, B) in zip(a, b): print(A + B)
Output
This will give the output −
20 20 20
- Related Articles
- How do I loop through a JSON file with multiple keys/sub-keys in Python?
- Python - Intersection of multiple lists
- Python program to iterate over multiple lists simultaneously?
- Loop through a Set using Javascript
- How do you Loop Through a Dictionary in Python?
- Loop through a hash table using Javascript
- How to loop through a menu list on a webpage using Selenium?
- Append multiple lists at once in Python
- How can I iterate through two lists in parallel in Python?
- How to loop through all the iframes elements of a page using jQuery?
- How to loop through an array in Java?
- How to print a name multiple times without loop statement using C language?
- How to create a triangle using Python for loop?
- Loop through an ArrayList using an Iterator in Java
- Loop through a HashMap using an Iterator in Java

Advertisements