Loop three lists at the same time?

D

Davy

Hi all,

I have three lists with the same length. Is there any method to loop
the three lists without a loop counter?

Best regards,
Davy
 
C

cokofreedom

Hi all,

I have three lists with the same length. Is there any method to loop
the three lists without a loop counter?

Best regards,
Davy

What exactly do you mean?

Are you trying to loop them together with the same ´count´. "for loop
in zip(1,2,3) kind of thing or something else.

Please either post a more descriptive question, or your current code.

Coko
 
G

Gabriel Genellina

I have three lists with the same length. Is there any method to loop
the three lists without a loop counter?

Try zip or itertools.izip:

py> L1 = ['a','b','c']
py> L2 = [1, 2, 3]
py> L3 = ['I', 'II', 'III']
py> from itertools import izip
py> for x,y,z in izip(L1,L2,L3):
.... print x,y,z
....
a 1 I
b 2 II
c 3 III
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,634
Latest member
RonnyBoelk

Latest Threads

Top