enumerate(iterable, start=0)
The enumerate function accepts as an input argument a sequence, an iterator or another object that supports iteration and returns an iterator of type "enumerate" composed of tuples formed by a counter (starting with the value start) and each of the values of the input iterator.
- iterable: iterator whose elements will be included as the second value of each tuple.
- start: initial value of the counter that will be included as the first value of each tuple.
The enumerate function returns an iterator of type enumerate.
We can create an enumerate from a list:
meses = ["ene", "feb", "mar"]
list(enumerate(meses))
With the start argument we can control the value of the counter to add to each tuple:
meses = ["may", "jun", "jul"]
list(enumerate(meses, start = 5))