ReferenceBuilt-in functions
enumerate()
Pairs each item with a running count, so you get the position and the item.
Signature
enumerate(iterable, start=0)Parameters
| Name | Means |
|---|---|
iterable | what to walk |
start | the first number, 0 by default |
Returns
An iterator of (index, item) pairs.
Example
Python
for i, name in enumerate(["Ada", "Grace"]):
print(i, name)
for n, name in enumerate(["Ada", "Grace"], start=1):
print(n, name)Output
0 Ada 1 Grace 1 Ada 2 Grace