美文网首页
python同时遍历两个list

python同时遍历两个list

作者: Time一柒 | 来源:发表于2019-05-08 16:09 被阅读0次

两个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

相关文章

  • python同时遍历两个list

    两个list, 有对应关系,希望同时完成遍历 用迭代器迭代的方法也不是不可以,python提供了更直观的方法: 可...

  • 039-什么是迭代

    在Python中,如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历...

  • 9-1什么是迭代

    在Python中,如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历...

  • 9、迭代

    在Python中,如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历...

  • 46-什么是迭代

    在Python中,如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历...

  • python list 遍历

  • Python 之杂文(长期更新)

    纯属记录 想同时遍历两个range 这里 len(time_list) - 1)相当于A range(1, ...

  • python同时遍历两个列表

    当需要同时遍历2个列表时,使用zip函数。例: i 36.33.32.158:59019

  • Python 同时枚举两个 list

    From: python同时枚举两个python列表?[https://blog.csdn.net/qq_3478...

  • python高级特性

    python高级特性 iteration迭代 对list,tuple的遍历被称为迭代。对list实现类似Java那...

网友评论

      本文标题:python同时遍历两个list

      本文链接:https://www.haomeiwen.com/subject/yscvoqtx.html