diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2023-12-13 18:11:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-13 18:11:52 (GMT) |
commit | 2111795d0c2dea0ade67d5d76f839102d68caa23 (patch) | |
tree | 666c2e0ba02358095ed02cdf07f375d899d7da2e /Doc/library/itertools.rst | |
parent | 480b4b359d710c74f31e2ffd7fc51750dcec7012 (diff) | |
download | cpython-2111795d0c2dea0ade67d5d76f839102d68caa23.zip cpython-2111795d0c2dea0ade67d5d76f839102d68caa23.tar.gz cpython-2111795d0c2dea0ade67d5d76f839102d68caa23.tar.bz2 |
Use match/case in grouper() recipe (gh-113059)
Use match/case in grouper() reciper
Diffstat (limited to 'Doc/library/itertools.rst')
-rw-r--r-- | Doc/library/itertools.rst | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 8a4254c..56c66f6 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -914,14 +914,15 @@ which incur interpreter overhead. # grouper('ABCDEFG', 3, incomplete='strict') --> ABC DEF ValueError # grouper('ABCDEFG', 3, incomplete='ignore') --> ABC DEF args = [iter(iterable)] * n - if incomplete == 'fill': - return zip_longest(*args, fillvalue=fillvalue) - elif incomplete == 'strict': - return zip(*args, strict=True) - elif incomplete == 'ignore': - return zip(*args) - else: - raise ValueError('Expected fill, strict, or ignore') + match incomplete: + case 'fill': + return zip_longest(*args, fillvalue=fillvalue) + case 'strict': + return zip(*args, strict=True) + case 'ignore': + return zip(*args) + case _: + raise ValueError('Expected fill, strict, or ignore') def sliding_window(iterable, n): # sliding_window('ABCDEFG', 4) --> ABCD BCDE CDEF DEFG |