Member-only story
Enumerate in Python
The enumerate() function in Python is a built-in utility that allows you to loop over an iterable (like a list, tuple, or string) and get the index and value of each item simultaneously. It is commonly used in for-loops.
Read the full story here: https://allwin-raju-12.medium.com/enumerate-in-python-8a61ce5a34fe?sk=461b686b96ab577d16707209d90767d3
Syntax:
enumerate(iterable, start=0)iterable: The sequence you want to enumerate.start: The starting value of the index (default is0).
Returns:
An enumerate object, which produces pairs containing an index and the corresponding item from the iterable.
Example Usage:
1. Basic Example with List:
fruits = ['apple', 'banana', 'cherry']
for index, fruit in enumerate(fruits):
print(index, fruit)Output:
0 apple
1 banana
2 cherry2. Custom Start Index:
for index, fruit in enumerate(fruits, start=1):
print(index, fruit)Output:
1 apple
2 banana
3 cherry







