Looping over two lists at once

0 votes
How can I loop over two lists in python at the same time?
May 15, 2018 in Python by kaalabilli
• 1,090 points
34 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You have to use the zip() function:

for (x, y) in zip(listx, listy):
    print (x, y)

The iteration stops after the shorter of the two lists is looped over.

answered May 15, 2018 by Nietzsche's daemon
• 4,260 points

Related Questions In Python

0 votes
1 answer

How can I iterate through two lists in Parallel

You have to use the zip function ...READ MORE

answered Apr 17, 2018 in Python by anonymous
40 views
0 votes
1 answer

Difference between two lists in python

difference = list(set(list1) - set(list2)) READ MORE

answered May 24, 2018 in Python by Nietzsche's daemon
• 4,260 points
259 views
0 votes
1 answer

Looping over a string in python

for c in "string": ...READ MORE

answered May 28, 2018 in Python by Nietzsche's daemon
• 4,260 points
6 views
0 votes
1 answer

How to calculate cosine similarity between two lists using Pythong?

You should try SciPy. It has a bunch ...READ MORE

answered Dec 17, 2018 in Python by charlie_brown
• 7,710 points
476 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
22 views
+4 votes
6 answers
0 votes
1 answer

Looping over dictionary values

You can loop over the dictionary and ...READ MORE

answered Apr 17, 2018 in Python by Nietzsche's daemon
• 4,260 points
14 views
0 votes
1 answer

Iterating over multiple lists

import itertools for item in itertools.chain(listone, listtwo): #lis ...READ MORE

answered Apr 25, 2018 in Python by Nietzsche's daemon
• 4,260 points
9 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.