[Python-checkins] r69278 - in python/branches/release30-maint: Doc/glossary.rst Doc/library/itertools.rst Lib/test/test_itertools.py

raymond.hettinger python-checkins at python.org
Wed Feb 4 20:42:15 CET 2009


Author: raymond.hettinger
Date: Wed Feb 4 20:42:15 2009
New Revision: 69278
Log:
Minor doc fixes.
Modified:
 python/branches/release30-maint/Doc/glossary.rst
 python/branches/release30-maint/Doc/library/itertools.rst
 python/branches/release30-maint/Lib/test/test_itertools.py
Modified: python/branches/release30-maint/Doc/glossary.rst
==============================================================================
--- python/branches/release30-maint/Doc/glossary.rst	(original)
+++ python/branches/release30-maint/Doc/glossary.rst	Wed Feb 4 20:42:15 2009
@@ -379,7 +379,7 @@
 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``).
Modified: python/branches/release30-maint/Doc/library/itertools.rst
==============================================================================
--- python/branches/release30-maint/Doc/library/itertools.rst	(original)
+++ python/branches/release30-maint/Doc/library/itertools.rst	Wed Feb 4 20:42:15 2009
@@ -229,7 +229,7 @@
 
 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 @@
 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"
Modified: python/branches/release30-maint/Lib/test/test_itertools.py
==============================================================================
--- python/branches/release30-maint/Lib/test/test_itertools.py	(original)
+++ python/branches/release30-maint/Lib/test/test_itertools.py	Wed Feb 4 20:42:15 2009
@@ -1220,8 +1220,8 @@
 ... 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 @@
 [0, 2, 4, 6]
 
 >>> nth('abcde', 3)
-['d']
+'d'
+
+>>> nth('abcde', 9) is None
+True
 
 >>> quantify(range(99), lambda x: x%2==0)
 50


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /