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
252 views

1 answer to this question.

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
90 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
623 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
30 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,720 points
1,356 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 334 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
28 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
33 views