This content originally appeared on DEV Community and was authored by Aditi Sharma
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.
This content originally appeared on DEV Community and was authored by Aditi Sharma
Aditi Sharma | Sciencx (2025-09-02T10:43:27+00:00) 🚀 Day 5 of My Python Learning Journey – Lists, zip(), and enumerate(). Retrieved from https://www.scien.cx/2025/09/02/%f0%9f%9a%80-day-5-of-my-python-learning-journey-lists-zip-and-enumerate/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.