Skip to main content

Command Palette

Search for a command to run...

Activity #30: Master Python List of Dictionaries Data Structure

Updated
4 min readView as Markdown
Activity #30: Master Python List of Dictionaries Data Structure

A list of dictionaries in Python provides an effective way to organize and manage related data. Each dictionary acts as an individual record, with keys representing attributes and values containing their corresponding data. By storing these dictionaries in a list, you can easily handle collections of records, allowing for straightforward iteration and access to specific attributes. This combination offers both flexibility and clarity, making it particularly useful for working with complex datasets.

Product Table using Python List of Dictionaries

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"},
    {"ID": 3, "Name": "Cellphone", "Category": "Electronics", "Price": "200", "Stock": "150", "Supplier Email": "supplier3@gmail.com"},
    {"ID": 4, "Name": "Notebook", "Category": "Stationery", "Price": "5", "Stock": "500", "Supplier Email": "supplier4@gmail.com"},
    {"ID": 5, "Name": "Running", "Category": "Apparel", "Price": "80", "Stock": "100", "Supplier Email": "supplier5@gmail.com"}
]
for product in products:
  print(f"ID: {product['ID']}, Name: {product['Name']}, Category: {product['Category']}, Price: {product['Price']}, Stock: {product['Stock']}, Supplier Email: {product['Supplier Email']},")

Employee Table using Python List of Dictionaries

employees = [
    {"ID": 1, "Name" : "John Doe", "Department" : "Sales", "Age" : "30", "Supplier Email" : "john.doe@company.com"},
    {"ID": 2, "Name" : "Jane Smith", "Department" : "Human Resources", "Age" : "25", "Supplier Email" : "jane.smith@company.com"},
    {"ID": 3, "Name": "Mark Johnson", "Department": "IT", "Age": "40", "Supplier Email": "mark.johnson@company.com"},
    {"ID": 4, "Name": "Lisa Wong", "Department": "Marketing", "Age": "28", "Supplier Email": "lisa.wong@company.com"},
    {"ID": 5, "Name": "Paul McDonald", "Department": "Finance", "Age": "35", "Supplier Email": "paul.mcdonald@company.com"}

]
for employee in employees:
  print(f"ID: {employee['ID']}, Name: {employee['Name']}, Department: {employee['Department']}, Age: {employee['Age']}, Supplier Email: {employee['Supplier Email']},")

Books Table using Python List of Dictionaries

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"},
    {"ID": 3, "Title" : "1984", "Author": "George Orwell", "Genre": "Dystopian", "Published Year": "1949", "ISBN": "978-0451524935", "Stock": "40", "Price": "9.99"},
    {"ID": 4, "Title" : "The catcher in the rye" , "Author": "J.D. Salinger", "Genre": "Fiction", "Published Year": "1951", "ISBN": "978-0316769488", "Stock": "25", "Price": "8.99"},
    {"ID": 5, "Title" : "A Brief History of Time", "Author": "Stephen Hawking ", "Genre" : "Non-Fiction", "Published Year": "1988", "ISBN": "978-0553380163", "Stock": "10", "Price": "18.99"}
]
for book in books:
  print(f"ID: {book['ID']}, Title: {book['Title']}, Author: {book['Author']}, Genre: {book['Genre']}, Published Year: {book['Published Year']}, ISBN: {book['ISBN']} ,Stock: {book['Stock']} Price: {book['Price']},")

University Table using Python List of Dictionaries

universities = [
    {"name": "University of the Philippines", "location": "Quezon City", "established year": 1908, "id": 1, "type": "Public", "website": "www.up.edu.ph"},
    {"name": "Ateneo de Manila University", "location": "Quezon City", "established year": 1859, "id": 2, "type": "Private", "website": "www.ateneo.edu"},
    {"name": "De La Salle University", "location": "Manila", "established year": 1911, "id": 3, "type": "Private", "website": "www.dlsu.edu.ph"},
    {"name": "University of Santo Tomas", "location": "Manila", "established year": 1611, "id": 4, "type": "Private", "website": "www.ust.edu.ph"},
    {"name": "Polytechnic University of the Philippines", "location": "Manila", "established year": 1904, "id": 5, "type": "Public", "website": "www.pup.edu.ph"}
]
for university in universities:
    print(f"Name: {university['name']}, Location: {university['location']}")

Restaurant Table using Python List of Dictionaries

restaurants = [
    {"ID" : "1", "Name" : "Viking Luxury Buffet", "Location" : "Pasay City", "Cuisine Type" : "Buffet", "Established Year" : "2011", "Website or Contact" : "www.vikings.ph"},
    {"ID" : "2", "Name" : "Antonio's Restaurant", "Location" : "Tagaytay", "Cuisine Type" : "Fine Dining", "Established Year" : "2002", "Website or Contact" : "www.antoniosrestaurant.ph"},
    {"ID" : "3", "Name" : "Mesa Filipino Moderne", "Location" : "Makati City", "Cuisine Type" : "Filipino", "Established Year" : "2009", "Website or Contact" : "www.mesa.ph"},
    {"ID" : "4", "Name" : "Manam Comfort Filipino", "Location" : "Quezon City", "Cuisine Type" : "Filipino", "Established Year" : "2013", "Website or Contact" : "www.manam.ph"},
    {"ID" : "5", "Name" : "Ramen Nagi", "Location" : "Various locations", "Cuisine Type" : "Japanese", "Established Year" : "2013", "Website or Contact" : "www.ramennagi.com.ph"}
]
for restaurant in restaurants:
    print(f"ID: {restaurant['ID']}, Name: {restaurant['Name']}, Location: {restaurant['Location']}, Established Year: {restaurant['Established Year']}, Website or Contact: {restaurant['Website or Contact']}")

GitHub Link: https://github.com/RomelUsigan/Master_Python_List_of_Dictionaries

More from this blog

Untitled Publication

66 posts