By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
When you start writing Python programs, storing single values in variables doesn't scale. You need to hold multiple related pieces of data and access them efficiently. Python gives you two primary tools: lists for ordered sequences and dictionaries for key-value lookups. Knowing which one to reach for will make your code cleaner and faster.
A list is an ordered collection of items where position matters. You access elements by their index, and Python uses zero-based indexing—the first item is at index 0. Negative indices count backward from the end: -1 gets the last item, -2 the second-to-last, and so on.
fruits = ["apple", "banana", "cherry"]
# Access
print(fruits[0]) # apple
print(fruits[-1]) # cherry (last item)
# Modify
fruits.append("date") # add to end
fruits.insert(1, "avocado") # insert at index
fruits.remove("banana") # remove by value
# Iterate
for i, fruit in enumerate(fruits):
print(f"{i+1}. {fruit}")
# List comprehension — concise filtering/mapping
upper = [f.upper() for f in fruits]
long_ones = [f for f in fruits if len(f) > 5]The code shows the core operations: append adds to the end, insert places an item at a specific position, and remove deletes by value. When you need to loop through a list and know the position of each item, use enumerate() instead of manually tracking an index. It's cleaner and less error-prone.
List comprehensions deserve special attention because you'll see them everywhere in Python code. They let you filter or transform a list in a single line. Instead of writing a loop with append calls, you write [expression for item in list if condition]. This is not just shorter—it's also more readable once you get used to the syntax.
A dictionary stores data as key-value pairs. Instead of accessing items by position, you access them by name. This is powerful when your data has structure: a user has a name, an age, a role. You don't care about order—you care about looking up values by their logical name.
user = {"name": "Alice", "age": 28, "role": "dev"}
# Access
print(user["name"]) # Alice
print(user.get("email", "N/A")) # N/A (safe default)
# Modify
user["email"] = "alice@example.com"
del user["role"]
# Iterate
for key, value in user.items():
print(f"{key}: {value}")Notice the difference between bracket access and the get() method. If you use user["email"] and the key doesn't exist, you get a KeyError and your program crashes. If you use user.get("email", "N/A"), you provide a safe default value. Use get() when you're not sure a key exists.
When you iterate over a dictionary, use the items() method to get both keys and values at once. This is more readable than accessing keys and then looking up each value separately.
Use a list when order matters; use a dict when you look things up by name.
If you're storing a sequence where position has meaning—a to-do list, search results, steps in a process—use a list. If you're storing related attributes that you'll access by name—configuration settings, user profiles, API responses—use a dictionary. Sometimes you'll use both: a list of dictionaries, where each dictionary represents a record with named fields.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.