zip will create pairs of elements when passed two lists, and will stop at the end of the shorter list.
zip can handle three or more lists as well!
code:
<span style="font-size:18px;">list_a = [3, 9, 17, 15, 19]
list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90]
for a, b in zip(list_a, list_b):
print max(a,b)</span>
本文介绍如何使用Python内置函数zip来处理多个列表,并演示了当列表长度不一时zip的行为特性。通过一个具体示例展示了如何遍历两个列表并比较每个对应元素的大小。
1175

被折叠的 条评论
为什么被折叠?



