Commit d04fa31f authored by Raymond Hettinger's avatar Raymond Hettinger

Minor doc fixes.

parent 1c62dc9d
No related merge requests found
......@@ -393,7 +393,7 @@ Glossary
also :term:`immutable`.
named tuple
Any tuple subclass whose indexable elements are also accessible using
Any tuple-like class whose indexable elements are also accessible using
named attributes (for example, :func:`time.localtime` returns a
tuple-like object where the *year* is accessible either with an
index such as ``t[0]`` or with a named attribute like ``t.tm_year``).
......
......@@ -206,7 +206,7 @@ For example::
.. method:: most_common([n])
Return a list of the *n* most common elements and their counts from the
most common to the least. If *n* not specified, :func:`most_common`
most common to the least. If *n* is not specified, :func:`most_common`
returns *all* elements in the counter. Elements with equal counts are
ordered arbitrarily::
......
......@@ -290,7 +290,7 @@ loops that truncate the stream.
class groupby(object):
# [k for k, g in groupby('AAAABBBCCDAABBB')] --> A B C D A B
# [(list(g)) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D
# [list(g) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D
def __init__(self, iterable, key=None):
if key is None:
key = lambda x: x
......@@ -591,8 +591,8 @@ which incur interpreter overhead.
return map(function, count(start))
def nth(iterable, n):
"Returns the nth item or empty list"
return list(islice(iterable, n, n+1))
"Returns the nth item or None"
return next(islice(iterable, n, None), None)
def quantify(iterable, pred=bool):
"Count how many times the predicate is true"
......
......@@ -1371,8 +1371,8 @@ Samuele
... return map(function, count(start))
>>> def nth(iterable, n):
... "Returns the nth item or empty list"
... return list(islice(iterable, n, n+1))
... "Returns the nth item or None"
... return next(islice(iterable, n, None), None)
>>> def quantify(iterable, pred=bool):
... "Count how many times the predicate is true"
......@@ -1469,7 +1469,10 @@ perform as purported.
[0, 2, 4, 6]
>>> nth('abcde', 3)
['d']
'd'
>>> nth('abcde', 9) is None
True
>>> quantify(range(99), lambda x: x%2==0)
50
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment