Python enumerate() Function

Takes a collection (lists, tuples, sets and dictionaries) and returns it is as an "enumerate object."  When using the enumerate object in a loop, each item in the enumerate object includes a counter, starting from 0 by default, and the value in the collection.

Syntax

Python
enumerate(iterable, start)

Parameters

ParameterDescription
iterable Required. The string value to search for within the given string
start Optional. The value at which to start the numbering. The default is 0.

Example

Python
seasons = ['Spring', 'Summer', 'Fall', 'Winter']
enumerated = list(enumerate(seasons))
print(enumerated)

# Start the counter at 10
enumerated = list(enumerate(seasons, 10))
print(enumerated)

Output

[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
[(10, 'Spring'), (11, 'Summer'), (12, 'Fall'), (13, 'Winter')]