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.