enumerate是枚举,迭代返回index和一个内容
zip是打包,迭代返回多个或一个内容
alist = [‘a1’, ‘a2’, ‘a3’]
blist = [‘b1’, ‘b2’, ‘b3’]
for i, (a, b) in enumerate(zip(alist, blist)):
print(i, a, b)
结果如下
0 a1 b1
1 a2 b2
2 a3 b3
enumerate是枚举,迭代返回index和一个内容
zip是打包,迭代返回多个或一个内容
alist = [‘a1’, ‘a2’, ‘a3’]
blist = [‘b1’, ‘b2’, ‘b3’]
for i, (a, b) in enumerate(zip(alist, blist)):
print(i, a, b)
结果如下
0 a1 b1
1 a2 b2
2 a3 b3