+ 1

Iterating the list more than once

I want to iterate the same list again while iterating another list. For example: l1 = "1234" for i, x in zip(l1, "howtodothat"): print(i + " " + x) Result will be 1 h 2 o 3 w 4 t But I want it to be: 1 h 2 o 3 w 4 t 1 o 2 d 3 o 4 t 1 h .... Any function for that in Python? Mert Yazıcı

3rd Jul 2019, 11:15 AM
Yusuf
Yusuf - avatar
4 Réponses
+ 6
from itertools import cycle i1 = "1234" i2 = "howtodothat" for i, j in zip(cycle(i1), i2): print(i, j)
3rd Jul 2019, 11:29 AM
Mert Yazıcı
Mert Yazıcı - avatar
+ 4
I found it when I was trying to find how permutations/combinations work.
3rd Jul 2019, 12:08 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 2
Thank you, how did you find it? =D
3rd Jul 2019, 11:44 AM
Yusuf
Yusuf - avatar
+ 2
https://code.sololearn.com/c1j8c6W2SoW0/?ref=app That's the program I am trying to write.
3rd Jul 2019, 11:58 AM
Yusuf
Yusuf - avatar