Python 把两个列表遍历为一个

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

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

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

类似:

复制代码
 list1 = [1,2,3,4]

list2 = [5,6,7,8]

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

  i3 = i1+i2

  print i3

猜你喜欢

转载自www.cnblogs.com/testing-BH/p/9289647.html