并行,使用zip函数。

l1=['1','2','3','4','5']
l2=['a','b','c','d','e']
l3=['qqq','www','eee','rrr','ttt']
l4=zip(l1,l2,l3)
for x,y,z in l4:
  print(x,y,z)
print(list(zip(l1,l2,l3)))   #[('1', 'a', 'qqq'), ('2', 'b', 'www'), ('3', 'c', 'eee'), ('4', 'd', 'rrr'), ('5', 'e', 'ttt')]

 

串行:使用itertools下的chain函数

from itertools import chain
l1=['1','2','3','4','5']
l2=['a','b','c','d','e']
l3=['qqq','www','eee','rrr','ttt']
l4=chain(l1,l2,l3)
for x in l4:
  print(x)
print(list(chain(l1,l2,l3)))    #['1', '2', '3', '4', '5', 'a', 'b', 'c', 'd', 'e', 'qqq', 'www', 'eee', 'rrr', 'ttt']

相关文章:

  • 2021-12-15
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2021-06-26
  • 2022-12-23
  • 2022-02-23
相关资源
相似解决方案