enumerate

Full name
enumerate
Library
Built-in
Syntax

enumerate(iterable, start=0)

Description

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.

Parameters
  • 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.
Result

The enumerate function returns an iterator of type enumerate.

Examples

We can create an enumerate from a list:

meses = ["ene", "feb", "mar"]
list(enumerate(meses))

Enumerate function. Example of use

 

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))

Enumerate function. Example of use

 

Submitted by admin on Mon, 01/21/2019 - 21:39