]> granicus.if.org Git - python/commitdiff
Minor doc fixups.
authorRaymond Hettinger <python@rcn.com>
Wed, 4 Feb 2009 10:52:32 +0000 (10:52 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 4 Feb 2009 10:52:32 +0000 (10:52 +0000)
Doc/library/collections.rst
Doc/library/itertools.rst
Lib/test/test_itertools.py

index 5a7c8c1b56b409eff35a46557343c5de45eb90c1..22f41f9af375c341989e8f1b6d270782f5eae36b 100644 (file)
@@ -218,7 +218,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::
 
index 78b10c7f878ffa307b238053ad9bc65e7318b13b..240baf03488acf342cb203ea37fb3bdedee3f551 100644 (file)
@@ -282,7 +282,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
@@ -675,8 +675,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 1ba43f7d18409c2c2e45d71bf79c9e3e8b9a3fc8..b79f70f2f4b494fbd663fe538aece58b38baab35 100644 (file)
@@ -1352,8 +1352,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"
@@ -1448,7 +1448,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