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)
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/KVB7SFL3ANJHAYGGGGNNQQEXM5BFQ2AQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to