Skip to content

Commit 9235f16

Browse files
author
raymond.hettinger
committed
Minor doc fixups.
git-svn-id: http://svn.python.org/projects/python/trunk@69271 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 05c6ab0 commit 9235f16

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

Doc/library/collections.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ For example::
218218
.. method:: most_common([n])
219219

220220
Return a list of the *n* most common elements and their counts from the
221-
most common to the least. If *n* not specified, :func:`most_common`
221+
most common to the least. If *n* is not specified, :func:`most_common`
222222
returns *all* elements in the counter. Elements with equal counts are
223223
ordered arbitrarily::
224224

Doc/library/itertools.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ loops that truncate the stream.
282282

283283
class groupby(object):
284284
# [k for k, g in groupby('AAAABBBCCDAABBB')] --> A B C D A B
285-
# [(list(g)) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D
285+
# [list(g) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D
286286
def __init__(self, iterable, key=None):
287287
if key is None:
288288
key = lambda x: x
@@ -675,8 +675,8 @@ which incur interpreter overhead.
675675
return imap(function, count(start))
676676

677677
def nth(iterable, n):
678-
"Returns the nth item or empty list"
679-
return list(islice(iterable, n, n+1))
678+
"Returns the nth item or None"
679+
return next(islice(iterable, n, None), None)
680680

681681
def quantify(iterable, pred=bool):
682682
"Count how many times the predicate is true"

Lib/test/test_itertools.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,8 @@ def __init__(self, newarg=None, *args):
13521352
... return imap(function, count(start))
13531353
13541354
>>> def nth(iterable, n):
1355-
... "Returns the nth item or empty list"
1356-
... return list(islice(iterable, n, n+1))
1355+
... "Returns the nth item or None"
1356+
... return next(islice(iterable, n, None), None)
13571357
13581358
>>> def quantify(iterable, pred=bool):
13591359
... "Count how many times the predicate is true"
@@ -1448,7 +1448,10 @@ def __init__(self, newarg=None, *args):
14481448
[0, 2, 4, 6]
14491449
14501450
>>> nth('abcde', 3)
1451-
['d']
1451+
'd'
1452+
1453+
>>> nth('abcde', 9) is None
1454+
True
14521455
14531456
>>> quantify(xrange(99), lambda x: x%2==0)
14541457
50

0 commit comments

Comments
 (0)