Skip to content

Commit a4d1ec1

Browse files
authored
add output for first example (#211)
1 parent e7bbb9b commit a4d1ec1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

enumerate.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ advanced programmers are unaware of it. It allows us to loop over
77
something and have an automatic counter. Here is an example:
88

99
.. code:: python
10+
11+
my_list = ['apple', 'banana', 'grapes', 'pear']
12+
for counter, value in enumerate(my_list):
13+
print counter, value
1014
11-
for counter, value in enumerate(some_list):
12-
print(counter, value)
15+
# Output:
16+
# 0 apple
17+
# 1 banana
18+
# 2 grapes
19+
# 3 pear
1320
14-
And there is more! ``enumerate`` also accepts an optional argument which
15-
makes it even more useful.
21+
And there is more! ``enumerate`` also accepts an optional argument that
22+
allows us to specify the starting index of the counter.
1623

1724
.. code:: python
1825
@@ -26,9 +33,9 @@ makes it even more useful.
2633
# 3 grapes
2734
# 4 pear
2835
29-
The optional argument allows us to tell ``enumerate`` from where to
30-
start the index. You can also create tuples containing the index and
31-
list item using a list. Here is an example:
36+
An example of where the optional argument of ``enumerate``comes in handy
37+
is creating tuples containing the index and list item using a list. Here
38+
is an example:
3239
3340
.. code:: python
3441

0 commit comments

Comments
 (0)