Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04e1012

Browse files
committed
Issue 11889: Clarify docs for enumerate.
2 parents 36a9de0 + 9d3df6d commit 04e1012

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

Doc/library/functions.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,13 @@ are always available. They are listed here in alphabetical order.
331331
:term:`iterator`, or some other object which supports iteration. The
332332
:meth:`__next__` method of the iterator returned by :func:`enumerate` returns a
333333
tuple containing a count (from *start* which defaults to 0) and the
334-
corresponding value obtained from iterating over *iterable*.
335-
336-
>>> for i, season in enumerate('Spring Summer Fall Winter'.split(), start=1):
337-
print(i, season)
338-
1 Spring
339-
2 Summer
340-
3 Fall
341-
4 Winter
334+
values obtained from iterating over *iterable*.
335+
336+
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
337+
>>> list(enumerate(seasons))
338+
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
339+
>>> list(enumerate(seasons, start=1))
340+
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
342341

343342
Equivalent to::
344343

0 commit comments

Comments
 (0)