Today, I deep-dived into Lists in Python and two powerful functions – zip() and enumerate().
🔹 What are Lists?
Lists are ordered, mutable collections that can store multiple items.
fruits = ["apple", "banana", "cherry"]
print(fruits) # ['apple', 'banana', 'cherry']
Some useful methods:
• append() → add an element
• insert() → insert at a specific index
• remove() → remove an element
• sort() → sort elements
• reverse() → reverse the order
🔹 enumerate() – cleaner looping
Instead of using a counter, enumerate() gives both index and value.
fruits = ["apple", "banana", "cherry"]
for index, fruit in enumerate(fruits):
print(index, fruit)
Output:
0 apple
1 banana
2 cherry
🔹 zip() – pairing data
When you want to iterate over multiple lists at once, zip() is a life-saver.
names = ["Alice", "Bob", "Charlie"]
scores = [85, 90, 95]
for name, score in zip(names, scores):
print(f"{name}: {score}")
Output:
Alice: 85
Bob: 90
Charlie: 95
🎯 Why this matters?
• Lists are one of the most fundamental data structures in Python.
• enumerate() improves readability.
• zip() simplifies working with parallel data.
Top comments (0)