]> granicus.if.org Git - python/commitdiff
Minor doc fixes.
authorRaymond Hettinger <python@rcn.com>
Wed, 4 Feb 2009 19:34:31 +0000 (19:34 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 4 Feb 2009 19:34:31 +0000 (19:34 +0000)
Doc/glossary.rst
Doc/library/itertools.rst
Lib/test/test_itertools.py

index 0eb31117502a1af0dbeb2ac26b78bfb1292273df..808993e18e842baded256a9a8a346d2ab5c48d89 100644 (file)
@@ -396,7 +396,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 871b0cb83a782f5232fab3b3171f57b8cda2a614..6e561992e980d4bedc8c77668a8675fa8a15af08 100644 (file)
@@ -221,7 +221,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
@@ -614,8 +614,8 @@ which incur interpreter overhead.
        return imap(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 a45e608170a3ea712ae94efa17cd7120813f57cc..91939e247e25b87006d87d6245061d3ba1e6d40f 100644 (file)
@@ -1201,8 +1201,8 @@ Samuele
 ...     return imap(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"
@@ -1318,7 +1318,10 @@ perform as purported.
 [0, 2, 4, 6]
 
 >>> nth('abcde', 3)
-['d']
+'d'
+
+>>> nth('abcde', 9) is None
+True
 
 >>> quantify(xrange(99), lambda x: x%2==0)
 50