Enumerating a list with a starting index is a common task in Python programming. In this blog post, we’ll explore different code examples that demonstrate how to enumerate a list with a starting index efficiently.
Example 1:
fruits = ['apple', 'banana', 'kiwi', 'orange'] for i, fruit in enumerate(fruits, 1): print(i, fruit)
Output:
1 apple
2 banana
3 kiwi
4 orange
Example 2:
numbers = [1, 2, 3, 4, 5] for i, num in enumerate(numbers, 10): print(i, num)
Output:
10 1
11 2
12 3
13 4
14 5