DEV Community

Aditi Sharma
Aditi Sharma

Posted on

πŸš€ Day 5 of My Python Learning Journey – Lists, zip(), and enumerate()

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)