@@ -1918,14 +1918,24 @@ are always available. They are listed here in alphabetical order.
1918
1918
>>> list(zip(('a', 'b', 'c'), (1, 2, 3), strict=True))
1919
1919
[('a', 1), ('b', 2), ('c', 3)]
1920
1920
1921
- Unlike the default behavior, it checks that the lengths of iterables are
1922
- identical, raising a :exc: `ValueError ` if they aren't:
1923
-
1924
- >>> list (zip (range (3 ), [' fee' , ' fi' , ' fo' , ' fum' ], strict = True ))
1921
+ Unlike the default behavior, it raises a :exc: `ValueError ` if one iterable
1922
+ is exhausted before the others:
1923
+
1924
+ >>> for item in zip (range (3 ), [' fee' , ' fi' , ' fo' , ' fum' ], strict = True ): # doctest: +SKIP
1925
+ ... print (item)
1926
+ ...
1927
+ (0, 'fee')
1928
+ (1, 'fi')
1929
+ (2, 'fo')
1925
1930
Traceback (most recent call last):
1926
1931
...
1927
1932
ValueError: zip() argument 2 is longer than argument 1
1928
1933
1934
+ ..
1935
+ This doctest is disabled because doctest does not support capturing
1936
+ output and exceptions in the same code unit.
1937
+ https://github.com/python/cpython/issues/65382
1938
+
1929
1939
Without the ``strict=True `` argument, any bug that results in iterables of
1930
1940
different lengths will be silenced, possibly manifesting as a hard-to-find
1931
1941
bug in another part of the program.
0 commit comments