]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Minor doc fixes.
authorRaymond Hettinger <python@rcn.com>
Wed, 4 Feb 2009 19:42:15 +0000 (19:42 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 4 Feb 2009 19:42:15 +0000 (19:42 +0000)
Doc/glossary.rst
Doc/library/itertools.rst
Lib/test/test_itertools.py

index 9e3cbeb92a3facf2e3c444cf35ef3fcde5456d52..a5dd54a2cffb6bc19cd3558b36cc160b2ac1b830 100644 (file)
@@ -379,7 +379,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``).
index f0bb251602efc2afc72f083a5585b00f044af3fc..d14d3d81c7ac461b6fd8899c15b55f41f96df336 100644 (file)
@@ -229,7 +229,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
@@ -530,8 +530,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"
index a675052cd875c0f9683591892f73a89ccd7f86bf..4e19e3a0fe47a22d13a0b6d865a5140dd4b2e225 100644 (file)
@@ -1220,8 +1220,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"
@@ -1337,7 +1337,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