mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Beautify grouper() recipe in docs.
This commit is contained in:
parent
749761e1a8
commit
883d27607a
2 changed files with 2 additions and 2 deletions
|
@ -634,7 +634,7 @@ which incur interpreter overhead.
|
||||||
def grouper(n, iterable, fillvalue=None):
|
def grouper(n, iterable, fillvalue=None):
|
||||||
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
|
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
|
||||||
args = [iter(iterable)] * n
|
args = [iter(iterable)] * n
|
||||||
return zip_longest(fillvalue=fillvalue, *args)
|
return zip_longest(*args, fillvalue=fillvalue)
|
||||||
|
|
||||||
def roundrobin(*iterables):
|
def roundrobin(*iterables):
|
||||||
"roundrobin('ABC', 'D', 'EF') --> A D E B F C"
|
"roundrobin('ABC', 'D', 'EF') --> A D E B F C"
|
||||||
|
|
|
@ -1370,7 +1370,7 @@ Samuele
|
||||||
>>> def grouper(n, iterable, fillvalue=None):
|
>>> def grouper(n, iterable, fillvalue=None):
|
||||||
... "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
|
... "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
|
||||||
... args = [iter(iterable)] * n
|
... args = [iter(iterable)] * n
|
||||||
... return zip_longest(fillvalue=fillvalue, *args)
|
... return zip_longest(*args, fillvalue=fillvalue)
|
||||||
|
|
||||||
>>> def roundrobin(*iterables):
|
>>> def roundrobin(*iterables):
|
||||||
... "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
|
... "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue