21 Apr
2020
21 Apr
'20
9:02 a.m.
21.04.20 11:49, Ram Rachum пише:
There is more interesting example:
x = iter(range(5)) y = [0] z = iter(range(5)) try: zipped = list(zip(x, y, z, strict=True)) except ValueError: # assuming that’s the exception you want? assert zipped == [(0, 0, 0)] assert next(x) == 2 print(next(z))
Should this print 1 or 2?
The simple implementation using zip_longest() would print 2, but more optimal implementation can print 1.
Your first assert is wrong.
Oh, right. zipped is not set when an exception is raised. It could be correct if rewrite the code: zipped = [] for item in zip(x, y, z, strict=True): zipped.append(item)