Topics / 🐍 Python Foundations / 🎛️ Level 7: Strings, while Loops, enumerate and zip

Python exercise · about 5 minutes · free

enumerate and zip: Ranked Scoreboard

Two lists that belong together, and you need the rank too. No index juggling required.

zip(a, b) pairs items from two lists. enumerate(items, start=1) numbers them. Together they replace most range(len(...)) loops.

Table. zip(names, scores): name, score; Zed | 500; Mia | 340; Kai | 120. Operation: enumerate(..., start=1). Result lines: line; 1. Zed - 500; 2. Mia - 340; 3. Kai - 120zip(names, scores)namescoreZed500Mia340Kai120linesline1. Zed - 5002. Mia - 3403. Kai - 120enumerate(..., start=1)
Your quest: Build lines like "1. Zed - 500" from names and scores, ranked from 1.
Starter code
names = ["Zed", "Mia", "Kai"]
scores = [500, 340, 120]
lines = []

Try it in your browser → Free. Sign in with Google to run it. Your code runs on your device.

In this level you'll learn:
More in Level 7: Strings, while Loops, enumerate and zip

Share on LinkedIn