You’ll be able to
- Iterate with
enumerate()for indexed loops - Loop over multiple sequences in parallel with
zip() - Reverse iteration with
reversed() - Sort iterables by custom keys with
sorted(..., key=...)
Loading lesson…
Why this matters
enumerate and zip are the mark of Pythonic code; reviewers flag for i in range(len(x)) on sight. dict.items() shows up in every config loader, template renderer, and ORM serializer in the ecosystem.
Common pitfalls
- Writing
for i in range(len(lst)): lst[i]instead ofenumerate(lst). It works but reads as non-Pythonic in code review. - Assuming
ziperrors on unequal lengths. It silently truncates; usezip(a, b, strict=True)on Python 3.10+ to catch mismatches. - Calling
.items()and unpacking wrong:for k, v in d.items()is correct;for k in d.items()gives you tuples.