How do you iterate with index and with two lists together?

Python lists, dictionaries and sets · Freshers and experienced

Model answer

enumerate(items, start=1) gives (index, item) pairs. zip(a, b) pairs items from two iterables and stops at the shortest (use itertools.zip_longest to go on, or zip(..., strict=True) in newer Python to raise on different lengths).

Learn this topic

Dictionaries, Tuples and Sets in Python in the course Python for Beginners: Learn to Code with Real Projects.

Sign in to add your own answer.

More questions