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.

IDNameCategoryPriceStockSupplier Email
1LaptopElectronics75050
2Desk ChairFurniture100200
3SmartwatchElectronics200150
4NotebookStationery5500
5Running ShoesApparel80100

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:

IDNameDepartmentAgeEmail
1John DoeSales30
2Jane SmithHuman Resources25
3Mark JohnsonIT40
4Lisa WongMarketing28
5Paul McDonaldFinance35

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:

IDTitleAuthorGenrePublished YearISBNStockPrice
1The Great GatsbyF. Scott FitzgeraldFiction1925978-07432735652015.99
2To Kill a MockingbirdHarper LeeFiction1960978-00609354673510.99
31984George OrwellDystopian1949978-0451524935409.99
4The Catcher in the RyeJ.D. SalingerFiction1951978-0316769488258.99
5A Brief History of TimeStephen HawkingNon-fiction1988978-05533801631018.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
]