Commit 04e1012e authored by Raymond Hettinger's avatar Raymond Hettinger

Issue 11889: Clarify docs for enumerate.

parents 36a9de04 9d3df6d5
...@@ -331,14 +331,13 @@ are always available. They are listed here in alphabetical order. ...@@ -331,14 +331,13 @@ are always available. They are listed here in alphabetical order.
:term:`iterator`, or some other object which supports iteration. The :term:`iterator`, or some other object which supports iteration. The
:meth:`__next__` method of the iterator returned by :func:`enumerate` returns a :meth:`__next__` method of the iterator returned by :func:`enumerate` returns a
tuple containing a count (from *start* which defaults to 0) and the tuple containing a count (from *start* which defaults to 0) and the
corresponding value obtained from iterating over *iterable*. values obtained from iterating over *iterable*.
>>> for i, season in enumerate('Spring Summer Fall Winter'.split(), start=1): >>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
print(i, season) >>> list(enumerate(seasons))
1 Spring [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
2 Summer >>> list(enumerate(seasons, start=1))
3 Fall [(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
4 Winter
Equivalent to:: Equivalent to::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment