Iterate over two list of different sizes in python

可紊 提交于 2019-12-08 21:49:34

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!