The enumerate function takes an iterable, assigns an index for each item in the iterable, and returns an enumerated object.
enumerate(iterable,start) #Where iterable can be a list,string,tuple, dictionary,set etc
An iterable is taken as the major input.An optional parameter start can be given to specify the starting index
Parameter | Description | Required / Optional |
---|---|---|
iterable | A collection that supports iteration | Required |
start | An integer. The enumeration starts with this parameter. Default is 0 |
Optional |
Each element in the iterable passed will be assigned a sequence index.
Input | Return Value |
---|---|
Iterable, start | returns an enumerated object and starts enumerating from start. |
letters = ['a','b','c','d']
enumeratedList = enumerate(letters)
print(type(enumeratedList))
Output:
letters = ['a','b','c','d']
enumeratedList = enumerate(letters,start=5)
for count,each_letter in enumeratedList:
print(count,each_letter)
Output:
5 a 6 b 7 c 8 d