Activity 20: Data Structure Again
Overview
This documentation aims to clarify the key differences between three important data structures: List, Object, and List of Objects. Each structure will be demonstrated using three tables of data: Products, Employees, and Books. These examples will help you visualize and comprehend how data can be structured differently for various use cases.
1. Product Data
Product Table Structure:
The table format organizes products by ID, Name, Category, Price, Stock, and Supplier Email.
ID | Name | Category | Price | Stock | Supplier Email |
1 | Laptop | Electronics | 750 | 50 | supplier1@gmail.com |
2 | Desk Chair | Furniture | 100 | 200 | supplier2@gmail.com |
3 | Smartwatch | Electronics | 200 | 150 | supplier3@gmail.com |
4 | Notebook | Stationery | 5 | 500 | supplier4@gmail.com |
5 | Running Shoes | Apparel | 80 | 100 | supplier5@gmail.com |
Product Data as Lists:
Here, each column is represented as a separate list. Each list contains data related to a single attribute (e.g., product names, prices).
product_id_list = [1, 2, 3, 4, 5]
product_name_list = ["Laptop", "Desk Chair", "Smartwatch", "Notebook", "Running Shoes"]
product_category_list = ["Electronics", "Furniture", "Electronics", "Stationery", "Apparel"]
product_price_list = [750, 100, 200, 5, 80]
product_stock_list = [50, 200, 150, 500, 100]
product_supplier_email_list = ["supplier1@gmail.com", "supplier2@gmail.com", "supplier3@gmail.com", "supplier4@gmail.com", "supplier5@gmail.com"]
Product Data as Objects:
In this structure, each product is stored as an object (dictionary), grouping all the attributes related to a single product.
product_object1 = {
"id": 1,
"name": "Laptop",
"category": "Electronics",
"price": 750,
"stock": 50,
"supplier_email": "supplier1@gmail.com"
}
Similar objects are created for each product (product_object2, product_object3, etc.).
Product Data as a List of Objects:
This structure organizes the data into a list where each element is an object representing a single product.
products = [
{
"id": 1,
"name": "Laptop",
"category": "Electronics",
"price": 750,
"stock": 50,
"supplier_email": "supplier1@gmail.com"
},
{
"id": 2,
"name": "Desk Chair",
"category": "Furniture",
"price": 100,
"stock": 200,
"supplier_email": "supplier2@gmail.com"
},
# ... Additional products
]
2. Employee Data
Employee Table Structure:
ID | Name | Department | Age | |
1 | John Doe | Sales | 30 | john.doe@company.com |
2 | Jane Smith | Human Resources | 25 | jane.smith@company.com |
3 | Mark Johnson | IT | 40 | mark.johnson@company.com |
4 | Lisa Wong | Marketing | 28 | lisa.wong@company.com |
5 | Paul McDonald | Finance | 35 | paul.mcdonald@company.com |
Employee Data as Lists:
employee_id_list = [1, 2, 3, 4, 5]
employee_name_list = ["John Doe", "Jane Smith", "Mark Johnson", "Lisa Wong", "Paul McDonald"]
employee_department_list = ["Sales", "Human Resources", "IT", "Marketing", "Finance"]
employee_age_list = [30, 25, 40, 28, 35]
employee_email_list = ["john.doe@company.com", "jane.smith@company.com", "mark.johnson@company.com", "lisa.wong@company.com", "paul.mcdonald@company.com"]
Employee Data as Objects:
employee_object1 = {
"id": 1,
"name": "John Doe",
"department": "Sales",
"age": 30,
"email": "john.doe@company.com"
}
Similar objects are created for each employee.
Employee Data as a List of Objects:
employees = [
{
"id": 1,
"name": "John Doe",
"department": "Sales",
"age": 30,
"email": "john.doe@company.com"
},
{
"id": 2,
"name": "Jane Smith",
"department": "Human Resources",
"age": 25,
"email": "jane.smith@company.com"
},
# ... Additional employees
]
3. Book Data
Book Table Structure:
ID | Title | Author | Genre | Published Year | ISBN | Stock | Price |
1 | The Great Gatsby | F. Scott Fitzgerald | Fiction | 1925 | 978-0743273565 | 20 | 15.99 |
2 | To Kill a Mockingbird | Harper Lee | Fiction | 1960 | 978-0060935467 | 35 | 10.99 |
3 | 1984 | George Orwell | Dystopian | 1949 | 978-0451524935 | 40 | 9.99 |
4 | The Catcher in the Rye | J.D. Salinger | Fiction | 1951 | 978-0316769488 | 25 | 8.99 |
5 | A Brief History of Time | Stephen Hawking | Non-fiction | 1988 | 978-0553380163 | 10 | 18.99 |
Book Data as Lists:
book_id_list = [1, 2, 3, 4, 5]
book_title_list = ["The Great Gatsby", "To Kill a Mockingbird", "1984", "The Catcher in the Rye", "A Brief History of Time"]
book_author_list = ["F. Scott Fitzgerald", "Harper Lee", "George Orwell", "J.D. Salinger", "Stephen Hawking"]
book_genre_list = ["Fiction", "Fiction", "Dystopian", "Fiction", "Non-fiction"]
book_published_year_list = [1925, 1960, 1949, 1951, 1988]
book_isbn_list = ["978-0743273565", "978-0060935467", "978-0451524935", "978-0316769488", "978-0553380163"]
book_stock_list = [20, 35, 40, 25, 10]
book_price_list = [15.99, 10.99, 9.99, 8.99, 18.99]
Book Data as Objects:
book_object1 = {
"id": 1,
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"genre": "Fiction",
"published_year": 1925,
"isbn": "978-0743273565",
"stock": 20,
"price": 15.99
}
Similar objects are created for each book.
Book Data as a List of Objects:
books = [
{
"id": 1,
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"genre": "Fiction",
"published_year": 1925,
"isbn": "978-0743273565",
"stock": 20,
"price": 15.99
},
{
"id": 2,
"title": "To Kill a Mockingbird",
"author": "Harper Lee",
"genre": "Fiction",
"published_year": 1960,
"isbn": "978-0060935467",
"stock": 35,
"price": 10.99
},
# ... Additional books
]