Enumerate Over A List In Python

list = [
    'one',
    'two',
    'three',
    'four'
]

# Loop over the list using the index and the item.
for i, item in enumerate(list):
    print(i, item.title())

This prints out the following:

0 One
1 Two
2 Three
3 Four

 

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
10 + 4 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.