
Python
Learning Level
Combine lists, dictionaries, and tuples to create powerful structures for real-world data.
Store multiple values for each key using lists.
# Student database with multiple grades
students = {
"Alice": {"grades": [95, 87, 92], "major": "CS"},
"Bob": {"grades": [78, 82, 80], "major": "Math"},
"Carol": {"grades": [88, 91, 89], "major": "Physics"}
}
# Access nested data
alice_grades = students["Alice"]["grades"]
print(alice_grades) # [95, 87, 92]
print(alice_grades[0]) # 95 (first grade)Store structured data for multiple items.
# List of products with details
products = [
{"name": "Laptop", "price": 1000, "stock": 5},
{"name": "Mouse", "price": 25, "stock": 50},
{"name": "Keyboard", "price": 75, "stock": 30}
]
# Access and modify
for product in products:
print(f"{product['name']}: ${product['price']}")
# Change stock
products[0]["stock"] = 4# Store user profile with nested data
user = {
"name": "Alice Johnson",
"age": 28,
"email": "alice@email.com",
"location": {"city": "New York", "country": "USA"},
"hobbies": ["reading", "coding", "hiking"],
"posts": [
{"title": "My first post", "likes": 5},
{"title": "Python tips", "likes": 12},
{"title": "Web development", "likes": 8}
]
}
# Access various levels
print(user["name"]) # Alice Johnson
print(user["location"]["city"]) # New York
print(user["hobbies"][0]) # reading
print(user["posts"][1]["likes"]) # 12# List of dictionaries (rows in a table)
data = [
{"id": 1, "name": "Item A", "price": 100},
{"id": 2, "name": "Item B", "price": 200}
]
# Dictionary of lists (columns)
inventory = {
"apples": [5, 3, 8],
"oranges": [2, 4, 6]
}
# Mixed nesting (most flexible)
config = {
"database": {
"host": "localhost",
"ports": [3306, 5432]
},
"features": ["auth", "api", "cache"]
}Ready to practice? Challenges | Quiz
Resources
Ojasa Mirai
Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.
Learn Deep • Build Real • Verify Skills • Launch Forward