Sometimes we need to keep count of iterators or the index position of an sequence so that we can use the index of the sequence later in the code as per need.Enumerate() function adds a counter to an iterable and returns it in a form of enumerate object. This can be directly used or can be converted into a list of tuples.
Enumerate in Python
Python has a built-in function to do this work which is enumerate() and it allows us to iterate over an iterable while keeping track of both the index and the value of each value in the iterable.
Syntax :
enumerate(iterable,start)
iterable – any object that is iterable
start(optional) – from index value to start, default value is 0
Return Value from enumerate()
enumerate() function adds counter to an iterable and returns it. The returned object is a enumerate object.
You can convert enumerate objects to list of tuple using list().
Login/Signup to comment