[Python-checkins] cpython (2.7): Issue 11889: Clarify docs for enumerate.

raymond.hettinger python-checkins at python.org
Sat Jun 25 14:57:12 CEST 2011


http://hg.python.org/cpython/rev/0ca8ffffd90b
changeset:   70968:0ca8ffffd90b
branch:      2.7
parent:      70965:9c337a4c650d
user:        Raymond Hettinger <python at rcn.com>
date:        Sat Jun 25 14:57:06 2011 +0200
summary:
  Issue 11889: Clarify docs for enumerate.

files:
  Doc/library/functions.rst |  13 ++++++-------
  1 files changed, 6 insertions(+), 7 deletions(-)


diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -341,14 +341,13 @@
    :term:`iterator`, or some other object which supports iteration.  The
    :meth:`!next` method of the iterator returned by :func:`enumerate` returns a
    tuple containing a count (from *start* which defaults to 0) and the
-   corresponding value obtained from iterating over *sequence*::
+   values obtained from iterating over *sequence*::
 
-      >>> for i, season in enumerate('Spring Summer Fall Winter'.split(), start=1):
-              print i, season
-      1 Spring
-      2 Summer
-      3 Fall
-      4 Winter
+      >>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
+      >>> list(enumerate(seasons))
+      [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
+      >>> list(enumerate(seasons, start=1))
+      [(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
 
    Equivalent to::
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list