enumerate |
| enumerate(iterable, start=0) |
Returns an enumerate object (built-in). |
| iterable | ?? |
| start | ?? |
| REMARKS |
| * This is a built-in function. * Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration. * The __next__() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over iterable. * For the Official documentation refer to python.org |
seasons = ['Spring', 'Summer', 'Fall', 'Winter']
list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
list(enumerate(seasons, start=1))
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
'Equivalent to:
def enumerate(iterable, start=0):
n = start
for elem in iterable:
yield n, elem
n += 1
grocery = ['bread', 'milk', 'butter']
enumerateGrocery = enumerate(grocery)
print(type(enumerateGrocery))
# converting to list
print(list(enumerateGrocery))
# changing the default counter
enumerateGrocery = enumerate(grocery, 10)
print(list(enumerateGrocery))
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited Top