两个list, 有对应关系,希望同时完成遍历

用迭代器迭代的方法也不是不可以,python提供了更直观的方法:

可以使用zip把两个list打包 ,

类似:

python 同时遍历俩个列表
 list1 = [1,2,3,4]

list2 = [5,6,7,8]

for (i1, i2) in zip(list1,list2):

  i3 = i1+i2

  print i3
python 同时遍历俩个列表

相关文章:

  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
猜你喜欢
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案