+ 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ı
4 odpowiedzi
+ 6
from itertools import cycle
i1 = "1234"
i2 = "howtodothat"
for i, j in zip(cycle(i1), i2):
print(i, j)
+ 4
I found it when I was trying to find how permutations/combinations work.
+ 2
Thank you, how did you find it? =D
+ 2
https://code.sololearn.com/c1j8c6W2SoW0/?ref=app
That's the program I am trying to write.