enumerate
Prev: divmod | Up: __builtins__ | Next: eval
Rel: all, any, filter, iter, aiter
Ref: docs.python.org — enumerate
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import enumerate
Overview & Signature
enumerate(iterable, start=0)
Return an enumerate object.
Usage
items = ["a", "b", "c"]
assert list(enumerate(items, start=1)) == [(1, "a"), (2, "b"), (3, "c")]
Gotchas
- Always prefer
for i, x in enumerate(xs):overfor i in range(len(xs)):: Works on any iterable (including generators) and supportsstart=1for 1-based numbering.
REPL Inspect
help(enumerate)
Linked from
- tuts/python3/__builtins__
- tuts/python3/__builtins__/__builtins__
- tuts/python3/__builtins__/aiter
- tuts/python3/__builtins__/all
- tuts/python3/__builtins__/anext
- tuts/python3/__builtins__/any
- tuts/python3/__builtins__/divmod
- tuts/python3/__builtins__/eval
- tuts/python3/__builtins__/filter
- tuts/python3/__builtins__/iter
- tuts/python3/__builtins__/len
- tuts/python3/__builtins__/map
- tuts/python3/__builtins__/next
- tuts/python3/__builtins__/reversed
- tuts/python3/__builtins__/sorted
- tuts/python3/__builtins__/zip
- tuts/python3/tutorials/core_fundamentals/control_flow
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/aiter Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/all Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/any Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/divmod Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/eval Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/filter Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/iter Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/anext links to this page; shared tags: #builtins