]> granicus.if.org Git - python/commitdiff
Issue 11889: Clarify docs for enumerate.
authorRaymond Hettinger <python@rcn.com>
Sat, 25 Jun 2011 12:57:06 +0000 (14:57 +0200)
committerRaymond Hettinger <python@rcn.com>
Sat, 25 Jun 2011 12:57:06 +0000 (14:57 +0200)
Doc/library/functions.rst

index 57748b6b49451987ba17b779c44d033e57e346dc..1c4793f42df1bdb297734abb230df1d5f25b8967 100644 (file)
@@ -341,14 +341,13 @@ available.  They are listed here in alphabetical order.
    :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*::
-
-      >>> for i, season in enumerate('Spring Summer Fall Winter'.split(), start=1):
-              print i, season
-      1 Spring
-      2 Summer
-      3 Fall
-      4 Winter
+   values obtained from iterating over *sequence*::
+
+      >>> 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::