6 Genius Python Hacks Using the zip() Function! ๐๐
1. Pairing Elements from Two Lists
names = ["Alice", "Bob", "Charlie"]
scores = [85, 92, 78]
for name, score in zip(names, scores):
print(f"{name}: {score}")
Alice: 85
Bob: 92
Charlie: 78
2. Unzipping Data into Separate Lists
pairs = [("Alice", 85), ("Bob", 92), ("Charlie", 78)]
names, scores = zip(*pairs)
print(names)
print(scores)
('Alice', 'โฆKeep reading with a 7-day free trial
Subscribe to Python Coding to keep reading this post and get 7 days of free access to the full post archives.


