![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements