Python Enumerate


Enumerate function

The enumerate() function return an enumerate object. The object must be a sequence, a list or an iterator.

Examples

Example 1

>>> my_list = ['a', 'b', 'c', 'd', 'e']
>>> list(enumerate(my_list))
[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e')]
>>> list(enumerate(my_list, start=2))
[(2, 'a'), (3, 'b'), (4, 'c'), (5, 'd'), (6, 'e')]
>>> 

Example 2

>>> my_list2 = [3, 4, 5]
>>> list(enumerate(my_list2))
>>> list(enumerate(my_list2))
[(0, 3), (1, 4), (2, 5)]
>>>