【发布时间】:2015-12-05 18:40:25
【问题描述】:
如何在使用 zip 扩展迭代后检查可迭代的大小是否相同?例如
>>> x = iter([1,2,3])
>>> y = iter([5,6,7,8])
>>> for i,j in zip(x,y):
... print i,j
...
1 5
2 6
3 7
在用完可迭代对象后执行next(x) 会引发错误,但我无法尝试将其排除,因为它不是Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
有什么方法可以一次性完成检查吗?
【问题讨论】:
-
你想对剩余的值做什么?
-
我正在尝试从 x 或 y 中提取所有未迭代的剩余值。
标签: python list zip iterable try-except