zip unzip?

K

KraftDiner

I have two lists...

a=[1,2,3]
b=[4,5,6]

n=0
for i in a:
print i, b[n]
n=n+1

how can i have two iterators on my for loop?
rather than have to use the counter n?
like:
for i,j in a,b:
print i, j

Do you know what I mean?
 
Z

ZeD

Ciao, KraftDiner! Che stavi dicendo?
I have two lists...

a=[1,2,3]
b=[4,5,6]

n=0
for i in a:
print i, b[n]
n=n+1

how can i have two iterators on my for loop?

for i,j in zip(a,b):
print i,j
 
F

Fredrik Lundh

KraftDiner said:
I have two lists...

a=[1,2,3]
b=[4,5,6]

n=0
for i in a:
print i, b[n]
n=n+1

how can i have two iterators on my for loop?
rather than have to use the counter n?
like:
for i,j in a,b:
print i, j

Do you know what I mean?

given your subject line, you seem to know what you mean.

for i,j in zip(a,b):
print i, j

</F>
 

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
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top