Value = [1,2,3,4,5,6]
content = ['a','b','c','d']
for a,b in itertools.zip_longest(Value , content):
print(a,b)
The Output that i get using the above code is as follows:
1 a
2 b
3 c
4 d
5 None
6 None
what I am Looking for is :
1 a
2 b
3 c
4 d
5 a
6 b
basically once one list is exhausted it should take the values again from starting. if any one could help would mean alot
解决方案
You can use itertools.cycle with zip instead:
import itertools
Value = [1,2,3,4,5,6]
content = ['a','b','c','d']
for a,b in zip(Value , itertools.cycle(content)):
print(a,b)
This outputs:
1 a
2 b
3 c
4 d
5 a
6 b