iterating over two sequences at once

Dan dan at
Sun Jul 25 19:11:00 CEST 2004

This is relatively simple, borrowing from my C++/PHP background:

str = "abcdefg"
str2 = "abcde"

i = 0
for c in str:
  print c, " ", str2[i]
  i += 2

But that is a C++/PHP way of doing things.

>From what I've seen of python, I almost expected python to allow:

for c, c2 in str, str2:

But it didn't. I would be very surprised if there isn't another clever
way of doing the same though.

My question to you is, how would you do this? And do you think I should
propose a PEP for supporting the above for loop syntax? It seems like a
relatively harmless feature in that it won't break existing code, but
then I am very new to python.


More information about the Python-list mailing list