names = ['Alice', 'Bob', 'Charlie']
ages = [25, 30, 35]
paired = list(zip(names, ages))
# [('Alice', 25), ('Bob', 30), ('Charlie', 35)]
# With three iterables
scores = [95, 87, 92]
combined = list(zip(names, ages, scores))
# [('Alice', 25, 95), ('Bob', 30, 87), ('Charlie', 35, 92)]a = [1, 2, 3, 4, 5]
b = ['a', 'b', 'c']
print(list(zip(a, b))) # [(1,'a'), (2,'b'), (3,'c')] — truncated!
# zip_longest fills with None (or custom fillvalue)
from itertools import zip_longest
print(list(zip_longest(a, b)))
# [(1,'a'), (2,'b'), (3,'c'), (4,None), (5,None)]
print(list(zip_longest(a, b, fillvalue='-')))
# [(1,'a'), (2,'b'), (3,'c'), (4,'-'), (5,'-')]pairs = [('a', 1), ('b', 2), ('c', 3)]
letters, numbers = zip(*pairs)
print(letters) # ('a', 'b', 'c')
print(numbers) # (1, 2, 3)
# Transpose a matrix
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
transposed = list(zip(*matrix))
# [(1, 4, 7), (2, 5, 8), (3, 6, 9)]fruits = ['apple', 'banana', 'cherry']
for index, fruit in enumerate(fruits):
print(f'{index}: {fruit}')
# 0: apple
# 1: banana
# 2: cherry
# Custom start index
for i, fruit in enumerate(fruits, start=1):
print(f'{i}. {fruit}')
# 1. apple
# 2. banana
# 3. cherry# Build dict from two lists
keys = ['name', 'age', 'city']
values = ['Alice', 25, 'NYC']
person = dict(zip(keys, values))
# {'name': 'Alice', 'age': 25, 'city': 'NYC'}
# Parallel iteration with index
names = ['a', 'b', 'c']
scores = [10, 20, 30]
for i, (name, score) in enumerate(zip(names, scores)):
print(f'#{i+1} {name}: {score}')
# Create indexed dict
indexed = {i: val for i, val in enumerate(fruits)}
# {0: 'apple', 1: 'banana', 2: 'cherry'}Given two lists `students = ['Alice', 'Bob', 'Charlie', 'Diana']` and `grades = [95, 87, 92]`, do the following: 1) Use zip to pair them (show truncation). 2) Use zip_longest with fillvalue='N/A' to pair all. 3) Build a dict using dict(zip()). 4) Unzip a list of pairs back into two tuples. 5) Use enumerate with start=1 to number the students. 6) Transpose a 3x4 matrix using zip(*matrix).