Skip to content
Justice Tech School

enumerate() and zip()

enumerate gives each item with its position, and start= changes the first number. zip walks through several lists together and stops at the shortest.

Example
names = ["Ada", "Tunde", "Zainab"]
for i, name in enumerate(names, start=1):
    print(i, name)
scores = [90, 75, 88]
for name, score in zip(names, scores):
    print(name, score)
print(dict(zip(names, scores)))

Result

1 Ada
2 Tunde
3 Zainab
Ada 90
Tunde 75
Zainab 88
{'Ada': 90, 'Tunde': 75, 'Zainab': 88}

Exercise

Get position and item together.

for i, x in (items):
    pass

Quiz Test

What does zip do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.