Data Structures in Real Projects
Data Structures in Real Projects
Learning lists, tuples, dictionaries, and sets is important.
But the real power comes when you use them to solve real problems.
In this lesson, you will see how data structures are used in practical beginner projects.
Why This Lesson Matters
Real programs need to store, update, search, and organize data.
Data structures make this possible.
Project 1: Contact List
Use a list to store names.
contacts = ["Tom", "Sara", "Mike"]
for contact in contacts:
print(contact)
Output
Tom
Sara
Mike
Why a List?
Because you need many names in one place.
Project 2: Product Information
Use a dictionary to store details.
product = {
"name": "Laptop",
"price": 900,
"stock": 5
}
print(product["name"])
print(product["price"])
Output
Laptop
900
Why a Dictionary?
Because each value has a label.
Project 3: Unique Tags
Use a set to remove duplicates.
tags = {"python", "coding", "python", "learn"}
print(tags)
Output
{'python', 'coding', 'learn'}
Why a Set?
Because only unique values are needed.
Project 4: Fixed Coordinates
Use a tuple for values that should not change.
location = (40.7, -74.0)
print(location)
Output
(40.7, -74.0)
Why a Tuple?
Because coordinates should stay fixed.
Project 5: Student Records
Use a list of dictionaries.
students = [
{"name": "Tom", "score": 85},
{"name": "Sara", "score": 92}
]
for student in students:
print(student["name"], student["score"])
Output
Tom 85
Sara 92
Why Nested Data?
Because each student has multiple details, and there are many students.
Project 6: Shopping Cart
Use a list of dictionaries.
cart = [
{"name": "Book", "price": 10},
{"name": "Pen", "price": 2}
]
total = 0
for item in cart:
total += item["price"]
print(total)
Output
12
Why This Works
The list stores many products.
Each dictionary stores details for one product.
Choosing the Right Structure
Use:
- List → many items
- Tuple → fixed values
- Dictionary → labeled data
- Set → unique values
Code Along
movies = [
{"title": "Inception", "year": 2010},
{"title": "Avatar", "year": 2009}
]
for movie in movies:
print(movie["title"])
Output
Inception
Avatar
Mini Challenge
Build a simple store.
Steps:
- Create a list of dictionaries with 2 products
- Each product should have:
name,price - Print each product name
- Add all prices
- Print the total
Expected output:
Book
Pen
12
Real World Use Case
Apps, websites, dashboards, stores, and games all depend on data structures to manage information.
Quiz
- Which structure stores unique values?
- Which structure uses key-value pairs?
- Which structure is best for fixed data?
- Why use nested data?
Assignment
Create a student records program using a list of dictionaries. Print each student name and score.
Summary
You learned how data structures are used in real projects and how to choose the right one for different problems.