From 76394fdc15959bc278d3583c3e3d1eea670269b4 Mon Sep 17 00:00:00 2001 From: Miguel Soares Date: Tue, 17 Jun 2025 11:41:25 +0000 Subject: [PATCH 1/3] Solved Lab --- .ipynb_checkpoints/README-checkpoint.md | 117 ++++++ ...ab-python-data-structures-checkpoint.ipynb | 387 ++++++++++++++++++ lab-python-data-structures.ipynb | 317 +++++++++++++- 3 files changed, 818 insertions(+), 3 deletions(-) create mode 100644 .ipynb_checkpoints/README-checkpoint.md create mode 100644 .ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb diff --git a/.ipynb_checkpoints/README-checkpoint.md b/.ipynb_checkpoints/README-checkpoint.md new file mode 100644 index 00000000..b66b7a56 --- /dev/null +++ b/.ipynb_checkpoints/README-checkpoint.md @@ -0,0 +1,117 @@ +![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png) + +# LAB | Python Data structures + +
+ +

Learning Goals

+
+ + This exercise allows you to practice and apply the concepts and techniques taught in class. + + Upon completion of this exercise, you will be able to: + + - Use different data structures such as lists, dictionaries, sets and tuples, to store and manipulate data. + - Access and modify data stored in data structures using indexing, slicing, or built-in methods. + +
+
+ +
+ +
+ +

Prerequisites

+
+Before this starting this lab, you should have learnt about: + +- Basic Python syntax +- Variables +- Data types, operators and structures + +
+
+ +
+ +## Introduction + +Welcome to your first data analytics bootcamp lab! In this lab, you will have the opportunity to dive into one of the fundamental building blocks of Python programming: data structures. + +As you may already know, data structures are collections of values that can be used to organize and manipulate data more efficiently, such as lists, dictionaries, sets, and tuples. + +Understanding data structures is essential to working with data in any programming language. It is a common practice to modify or manipulate data structures when performing various operations, such as filtering data, performing calculations, or extracting specific data elements. + +Through a series of lab exercises, you will have the opportunity to apply the concepts and techniques learned in class and gain a solid understanding of data structures. + +
+ +**Happy coding!** :heart: + + + +## Requirements + +- Fork this repo +- Clone it to your machine + + +## Getting Started + +Complete the challenges in the notebook. Follow the instructions and add your code and explanations as necessary. + +## Submission + +- Upon completion, run the following commands: + +```bash +git add . +git commit -m "Solved lab" +git push origin master +``` + +- Paste the link of your lab in Student Portal. + +## FAQs +
+ I am stuck in the exercise and don't know how to solve the problem or where to start. +
+ + If you are stuck in your code and don't know how to solve the problem or where to start, you should take a step back and try to form a clear question about the specific issue you are facing. This will help you narrow down the problem and come up with potential solutions. + + + For example, is it a concept that you don't understand, or are you receiving an error message that you don't know how to fix? It is usually helpful to try to state the problem as clearly as possible, including any error messages you are receiving. This can help you communicate the issue to others and potentially get help from classmates or online resources. + + + Once you have a clear understanding of the problem, you will be able to start working toward the solution. + + [Back to top](#faqs) + +
+ + +
+ I am unable to push changes to the repository. What should I do? +
+ +There are a couple of possible reasons why you may be unable to *push* changes to a Git repository: + +1. **You have not committed your changes:** Before you can push your changes to the repository, you need to commit them using the `git commit` command. Make sure you have committed your changes and try pushing again. To do this, run the following terminal commands from the project folder: + ```bash + git add . + git commit -m "Your commit message" + git push + ``` +2. **You do not have permission to push to the repository:** If you have cloned the repository directly from the main Ironhack repository without making a *Fork* first, you do not have write access to the repository. +To check which remote repository you have cloned, run the following terminal command from the project folder: + ```bash + git remote -v + ``` +If the link shown is the same as the main Ironhack repository, you will need to fork the repository to your GitHub account first and then clone your fork to your local machine to be able to push the changes. + +**Note**: You should make a copy of your local code to avoid losing it in the process. + + [Back to top](#faqs) + +
+ diff --git a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb new file mode 100644 index 00000000..7a88661d --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,387 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "# Lab | Data Structures " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise: Managing Customer Orders\n", + "\n", + "As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "\n", + "2. Create an empty dictionary called `inventory`.\n", + "\n", + "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", + "\n", + "4. Create an empty set called `customer_orders`.\n", + "\n", + "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n", + "\n", + "6. Print the products in the `customer_orders` set.\n", + "\n", + "7. Calculate the following order statistics:\n", + " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", + " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", + " \n", + " Store these statistics in a tuple called `order_status`.\n", + "\n", + "8. Print the order statistics using the following format:\n", + " ```\n", + " Order Statistics:\n", + " Total Products Ordered: \n", + " Percentage of Products Ordered: % \n", + " ```\n", + "\n", + "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "\n", + "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "\n", + "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"T-shirt\", \"Mug\", \"Hat\", \"Book\", \"Keychain\"]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2 Create an empty dictionary called `inventory`." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {} " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values. " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Input T-shirts quantity: 2\n", + "Input Mug quantity: 3\n", + "Input Hat quantity: 4\n", + "Input Book quantity: 1\n", + "Input Keychain quantity: 3\n" + ] + } + ], + "source": [ + "inventory[products[0]] = int(input(\"Input T-shirts quantity: \"))\n", + "inventory[products[1]] = int(input(\"Input Mug quantity: \"))\n", + "inventory[products[2]] = int(input(\"Input Hat quantity: \"))\n", + "inventory[products[3]] = int(input(\"Input Book quantity: \"))\n", + "inventory[products[4]] = int(input(\"Input Keychain quantity: \"))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'T-shirt': 2, 'Mug': 3, 'Hat': 4, 'Book': 1, 'Keychain': 3}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4 Create an empty set called `customer_orders`." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain mug\n", + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain hat\n", + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Successe\n" + ] + } + ], + "source": [ + "Item1 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", + "Item2 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", + "Item3 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", + "if Item1 and Item2 and Item3 in products:\n", + " customer_orders.update([Item1,Item2,Item3])\n", + " print(\"Successe\")" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [], + "source": [ + "# customer_orders.difference_update([\"Mug\", \"Hat\", \"Book\"]) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 6. Print the products in the `customer_orders` set." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Mug', 'Hat', 'Book'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 7. Calculate the following order statistics:\n", + " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", + " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products." + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "Total_Products_Ordered = len(customer_orders)\n", + "print(Total_Products_Ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "23%\n" + ] + } + ], + "source": [ + "Percentage_of_Products_Ordered = Total_Products_Ordered / sum(inventory.values()) * 100\n", + "print(str(round(Percentage_of_Products_Ordered)) + \"%\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 8. Print the order statistics using the following format:\n", + " ```\n", + " Order Statistics:\n", + " Total Products Ordered: \n", + " Percentage of Products Ordered: % \n", + " ```" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 23%\n" + ] + } + ], + "source": [ + "print(f\"Order Statistics:\\nTotal Products Ordered: {Total_Products_Ordered}\\nPercentage of Products Ordered: {round(Percentage_of_Products_Ordered)}%\")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly." + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "metadata": {}, + "outputs": [], + "source": [ + "for item in customer_orders & inventory.keys():\n", + " inventory[item] -= 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 10. Print the updated inventory, displaying the quantity of each product on separate lines." + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_items([('T-shirt', 2), ('Mug', 3), ('Hat', 4), ('Book', 1), ('Keychain', 3)])\n" + ] + } + ], + "source": [ + "# Before\n", + "print(inventory.items())" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_items([('T-shirt', 2), ('Mug', 2), ('Hat', 3), ('Book', 0), ('Keychain', 3)])\n" + ] + } + ], + "source": [ + "# After:\n", + "print(inventory.items())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..7a88661d 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,13 +50,324 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"T-shirt\", \"Mug\", \"Hat\", \"Book\", \"Keychain\"]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2 Create an empty dictionary called `inventory`." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {} " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values. " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Input T-shirts quantity: 2\n", + "Input Mug quantity: 3\n", + "Input Hat quantity: 4\n", + "Input Book quantity: 1\n", + "Input Keychain quantity: 3\n" + ] + } + ], + "source": [ + "inventory[products[0]] = int(input(\"Input T-shirts quantity: \"))\n", + "inventory[products[1]] = int(input(\"Input Mug quantity: \"))\n", + "inventory[products[2]] = int(input(\"Input Hat quantity: \"))\n", + "inventory[products[3]] = int(input(\"Input Book quantity: \"))\n", + "inventory[products[4]] = int(input(\"Input Keychain quantity: \"))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'T-shirt': 2, 'Mug': 3, 'Hat': 4, 'Book': 1, 'Keychain': 3}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4 Create an empty set called `customer_orders`." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain mug\n", + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain hat\n", + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Successe\n" + ] + } + ], + "source": [ + "Item1 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", + "Item2 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", + "Item3 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", + "if Item1 and Item2 and Item3 in products:\n", + " customer_orders.update([Item1,Item2,Item3])\n", + " print(\"Successe\")" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [], + "source": [ + "# customer_orders.difference_update([\"Mug\", \"Hat\", \"Book\"]) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 6. Print the products in the `customer_orders` set." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Mug', 'Hat', 'Book'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 7. Calculate the following order statistics:\n", + " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", + " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products." + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "Total_Products_Ordered = len(customer_orders)\n", + "print(Total_Products_Ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "23%\n" + ] + } + ], + "source": [ + "Percentage_of_Products_Ordered = Total_Products_Ordered / sum(inventory.values()) * 100\n", + "print(str(round(Percentage_of_Products_Ordered)) + \"%\" )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 8. Print the order statistics using the following format:\n", + " ```\n", + " Order Statistics:\n", + " Total Products Ordered: \n", + " Percentage of Products Ordered: % \n", + " ```" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 23%\n" + ] + } + ], + "source": [ + "print(f\"Order Statistics:\\nTotal Products Ordered: {Total_Products_Ordered}\\nPercentage of Products Ordered: {round(Percentage_of_Products_Ordered)}%\")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly." + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "metadata": {}, + "outputs": [], + "source": [ + "for item in customer_orders & inventory.keys():\n", + " inventory[item] -= 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 10. Print the updated inventory, displaying the quantity of each product on separate lines." + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_items([('T-shirt', 2), ('Mug', 3), ('Hat', 4), ('Book', 1), ('Keychain', 3)])\n" + ] + } + ], + "source": [ + "# Before\n", + "print(inventory.items())" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_items([('T-shirt', 2), ('Mug', 2), ('Hat', 3), ('Book', 0), ('Keychain', 3)])\n" + ] + } + ], + "source": [ + "# After:\n", + "print(inventory.items())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -68,7 +379,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.5" } }, "nbformat": 4, From 4281db45b62b15a8970dc362f21c2d01a59498ec Mon Sep 17 00:00:00 2001 From: Miguel Soares Date: Tue, 17 Jun 2025 14:41:37 +0000 Subject: [PATCH 2/3] Solved Lab --- .ipynb_checkpoints/README-checkpoint.md | 117 ------------------ ...ab-python-data-structures-checkpoint.ipynb | 69 +++++++---- lab-python-data-structures.ipynb | 56 +++++---- 3 files changed, 77 insertions(+), 165 deletions(-) delete mode 100644 .ipynb_checkpoints/README-checkpoint.md diff --git a/.ipynb_checkpoints/README-checkpoint.md b/.ipynb_checkpoints/README-checkpoint.md deleted file mode 100644 index b66b7a56..00000000 --- a/.ipynb_checkpoints/README-checkpoint.md +++ /dev/null @@ -1,117 +0,0 @@ -![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png) - -# LAB | Python Data structures - -
- -

Learning Goals

-
- - This exercise allows you to practice and apply the concepts and techniques taught in class. - - Upon completion of this exercise, you will be able to: - - - Use different data structures such as lists, dictionaries, sets and tuples, to store and manipulate data. - - Access and modify data stored in data structures using indexing, slicing, or built-in methods. - -
-
- -
- -
- -

Prerequisites

-
-Before this starting this lab, you should have learnt about: - -- Basic Python syntax -- Variables -- Data types, operators and structures - -
-
- -
- -## Introduction - -Welcome to your first data analytics bootcamp lab! In this lab, you will have the opportunity to dive into one of the fundamental building blocks of Python programming: data structures. - -As you may already know, data structures are collections of values that can be used to organize and manipulate data more efficiently, such as lists, dictionaries, sets, and tuples. - -Understanding data structures is essential to working with data in any programming language. It is a common practice to modify or manipulate data structures when performing various operations, such as filtering data, performing calculations, or extracting specific data elements. - -Through a series of lab exercises, you will have the opportunity to apply the concepts and techniques learned in class and gain a solid understanding of data structures. - -
- -**Happy coding!** :heart: - - - -## Requirements - -- Fork this repo -- Clone it to your machine - - -## Getting Started - -Complete the challenges in the notebook. Follow the instructions and add your code and explanations as necessary. - -## Submission - -- Upon completion, run the following commands: - -```bash -git add . -git commit -m "Solved lab" -git push origin master -``` - -- Paste the link of your lab in Student Portal. - -## FAQs -
- I am stuck in the exercise and don't know how to solve the problem or where to start. -
- - If you are stuck in your code and don't know how to solve the problem or where to start, you should take a step back and try to form a clear question about the specific issue you are facing. This will help you narrow down the problem and come up with potential solutions. - - - For example, is it a concept that you don't understand, or are you receiving an error message that you don't know how to fix? It is usually helpful to try to state the problem as clearly as possible, including any error messages you are receiving. This can help you communicate the issue to others and potentially get help from classmates or online resources. - - - Once you have a clear understanding of the problem, you will be able to start working toward the solution. - - [Back to top](#faqs) - -
- - -
- I am unable to push changes to the repository. What should I do? -
- -There are a couple of possible reasons why you may be unable to *push* changes to a Git repository: - -1. **You have not committed your changes:** Before you can push your changes to the repository, you need to commit them using the `git commit` command. Make sure you have committed your changes and try pushing again. To do this, run the following terminal commands from the project folder: - ```bash - git add . - git commit -m "Your commit message" - git push - ``` -2. **You do not have permission to push to the repository:** If you have cloned the repository directly from the main Ironhack repository without making a *Fork* first, you do not have write access to the repository. -To check which remote repository you have cloned, run the following terminal command from the project folder: - ```bash - git remote -v - ``` -If the link shown is the same as the main Ironhack repository, you will need to fork the repository to your GitHub account first and then clone your fork to your local machine to be able to push the changes. - -**Note**: You should make a copy of your local code to avoid losing it in the process. - - [Back to top](#faqs) - -
- diff --git a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb index 7a88661d..f1dd29eb 100644 --- a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 42, "metadata": {}, "outputs": [], "source": [ @@ -76,7 +76,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ @@ -92,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 48, "metadata": {}, "outputs": [ { @@ -102,8 +102,8 @@ "Input T-shirts quantity: 2\n", "Input Mug quantity: 3\n", "Input Hat quantity: 4\n", - "Input Book quantity: 1\n", - "Input Keychain quantity: 3\n" + "Input Book quantity: 5\n", + "Input Keychain quantity: 1\n" ] } ], @@ -117,14 +117,14 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 50, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'T-shirt': 2, 'Mug': 3, 'Hat': 4, 'Book': 1, 'Keychain': 3}\n" + "{'T-shirt': 2, 'Mug': 3, 'Hat': 4, 'Book': 5, 'Keychain': 1}\n" ] } ], @@ -141,7 +141,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ @@ -157,16 +157,16 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ - "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain mug\n", - "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain hat\n", - "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain book\n" + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain keychain\n", + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain book\n", + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain hat\n" ] }, { @@ -188,7 +188,7 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -204,14 +204,14 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 60, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'Mug', 'Hat', 'Book'}\n" + "{'Keychain', 'Hat', 'Book'}\n" ] } ], @@ -230,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 63, "metadata": {}, "outputs": [ { @@ -248,14 +248,14 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 65, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "23%\n" + "20%\n" ] } ], @@ -278,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 68, "metadata": {}, "outputs": [ { @@ -287,7 +287,7 @@ "text": [ "Order Statistics:\n", "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 23%\n" + "Percentage of Products Ordered: 20%\n" ] } ], @@ -304,12 +304,27 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": 71, "metadata": {}, "outputs": [], "source": [ - "for item in customer_orders & inventory.keys():\n", - " inventory[item] -= 1" + "# for item in customer_orders & inventory.keys():\n", + " # inventory[item] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [], + "source": [ + "# Check and subtract manually\n", + "if Item1 in inventory:\n", + " inventory[Item1] -= 1\n", + "if Item2 in inventory:\n", + " inventory[Item2] -= 1\n", + "if Item3 in inventory:\n", + " inventory[Item3] -= 1" ] }, { @@ -321,14 +336,14 @@ }, { "cell_type": "code", - "execution_count": 130, + "execution_count": 97, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "dict_items([('T-shirt', 2), ('Mug', 3), ('Hat', 4), ('Book', 1), ('Keychain', 3)])\n" + "dict_items([('T-shirt', 2), ('Mug', 3), ('Hat', 2), ('Book', 3), ('Keychain', -1)])\n" ] } ], @@ -339,14 +354,14 @@ }, { "cell_type": "code", - "execution_count": 134, + "execution_count": 99, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "dict_items([('T-shirt', 2), ('Mug', 2), ('Hat', 3), ('Book', 0), ('Keychain', 3)])\n" + "dict_items([('T-shirt', 2), ('Mug', 3), ('Hat', 2), ('Book', 3), ('Keychain', -1)])\n" ] } ], diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 7a88661d..d54a7d85 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -76,7 +76,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -100,10 +100,10 @@ "output_type": "stream", "text": [ "Input T-shirts quantity: 2\n", - "Input Mug quantity: 3\n", - "Input Hat quantity: 4\n", - "Input Book quantity: 1\n", - "Input Keychain quantity: 3\n" + "Input Mug quantity: 1\n", + "Input Hat quantity: 3\n", + "Input Book quantity: 4\n", + "Input Keychain quantity: 5\n" ] } ], @@ -124,7 +124,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'T-shirt': 2, 'Mug': 3, 'Hat': 4, 'Book': 1, 'Keychain': 3}\n" + "{'T-shirt': 2, 'Mug': 1, 'Hat': 3, 'Book': 4, 'Keychain': 5}\n" ] } ], @@ -164,8 +164,8 @@ "name": "stdin", "output_type": "stream", "text": [ - "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain mug\n", "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain hat\n", + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain mug\n", "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain book\n" ] }, @@ -188,7 +188,7 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -211,7 +211,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'Mug', 'Hat', 'Book'}\n" + "{'Book', 'Mug', 'Hat'}\n" ] } ], @@ -230,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -248,14 +248,14 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "23%\n" + "20%\n" ] } ], @@ -278,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -287,7 +287,7 @@ "text": [ "Order Statistics:\n", "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 23%\n" + "Percentage of Products Ordered: 20%\n" ] } ], @@ -304,12 +304,26 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "# for item in customer_orders & inventory.keys():\n", + " # inventory[item] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 42, "metadata": {}, "outputs": [], "source": [ - "for item in customer_orders & inventory.keys():\n", - " inventory[item] -= 1" + "if Item1 in inventory and Item1 in customer_orders:\n", + " inventory[Item1] -= 1\n", + "if Item2 in inventory and Item2 in customer_orders:\n", + " inventory[Item2] -= 1\n", + "if Item3 in inventory and Item3 in customer_orders:\n", + " inventory[Item3] -= 1" ] }, { @@ -321,14 +335,14 @@ }, { "cell_type": "code", - "execution_count": 130, + "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "dict_items([('T-shirt', 2), ('Mug', 3), ('Hat', 4), ('Book', 1), ('Keychain', 3)])\n" + "dict_items([('T-shirt', 2), ('Mug', -1), ('Hat', 1), ('Book', 2), ('Keychain', 5)])\n" ] } ], @@ -339,14 +353,14 @@ }, { "cell_type": "code", - "execution_count": 134, + "execution_count": 47, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "dict_items([('T-shirt', 2), ('Mug', 2), ('Hat', 3), ('Book', 0), ('Keychain', 3)])\n" + "dict_items([('T-shirt', 2), ('Mug', -1), ('Hat', 1), ('Book', 2), ('Keychain', 5)])\n" ] } ], From c192a0b7f7099b2bdbc6fdc8df2393a4baa64831 Mon Sep 17 00:00:00 2001 From: Miguel Soares Date: Tue, 17 Jun 2025 19:57:50 +0000 Subject: [PATCH 3/3] Solved Lab v2 --- ...ab-python-data-structures-checkpoint.ipynb | 83 ++++++++++++------- lab-python-data-structures.ipynb | 70 ++++++++++------ 2 files changed, 98 insertions(+), 55 deletions(-) diff --git a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb index f1dd29eb..c78d8635 100644 --- a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -76,7 +76,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -92,18 +92,18 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ - "Input T-shirts quantity: 2\n", + "Input T-shirts quantity: 4\n", "Input Mug quantity: 3\n", - "Input Hat quantity: 4\n", - "Input Book quantity: 5\n", - "Input Keychain quantity: 1\n" + "Input Hat quantity: 2\n", + "Input Book quantity: 1\n", + "Input Keychain quantity: 5\n" ] } ], @@ -117,14 +117,14 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'T-shirt': 2, 'Mug': 3, 'Hat': 4, 'Book': 5, 'Keychain': 1}\n" + "{'T-shirt': 4, 'Mug': 3, 'Hat': 2, 'Book': 1, 'Keychain': 5}\n" ] } ], @@ -141,7 +141,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -157,16 +157,16 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ - "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain keychain\n", - "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain book\n", - "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain hat\n" + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain mug\n", + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain hat\n", + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain book\n" ] }, { @@ -181,14 +181,14 @@ "Item1 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", "Item2 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", "Item3 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", - "if Item1 and Item2 and Item3 in products:\n", + "if Item1 in products and Item2 in products and Item3 in products:\n", " customer_orders.update([Item1,Item2,Item3])\n", " print(\"Successe\")" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -204,14 +204,14 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'Keychain', 'Hat', 'Book'}\n" + "{'Book', 'Mug', 'Hat'}\n" ] } ], @@ -230,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -248,7 +248,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -278,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -304,7 +304,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ @@ -314,16 +314,15 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ - "# Check and subtract manually\n", - "if Item1 in inventory:\n", + "if Item1 in inventory and Item1 in customer_orders:\n", " inventory[Item1] -= 1\n", - "if Item2 in inventory:\n", + "if Item2 in inventory and Item2 in customer_orders:\n", " inventory[Item2] -= 1\n", - "if Item3 in inventory:\n", + "if Item3 in inventory and Item3 in customer_orders:\n", " inventory[Item3] -= 1" ] }, @@ -336,14 +335,14 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "dict_items([('T-shirt', 2), ('Mug', 3), ('Hat', 2), ('Book', 3), ('Keychain', -1)])\n" + "dict_items([('T-shirt', 4), ('Mug', 3), ('Hat', 2), ('Book', 1), ('Keychain', 5)])\n" ] } ], @@ -354,14 +353,14 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "dict_items([('T-shirt', 2), ('Mug', 3), ('Hat', 2), ('Book', 3), ('Keychain', -1)])\n" + "dict_items([('T-shirt', 4), ('Mug', 2), ('Hat', 1), ('Book', 0), ('Keychain', 5)])\n" ] } ], @@ -370,6 +369,28 @@ "print(inventory.items())" ] }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "T-shirt: 4\n", + "Mug: 2\n", + "Hat: 1\n", + "Book: 0\n", + "Keychain: 5\n" + ] + } + ], + "source": [ + "for product, qty in inventory.items():\n", + " print(f\"{product}: {qty}\")" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index d54a7d85..c78d8635 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -76,7 +76,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -92,17 +92,17 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ - "Input T-shirts quantity: 2\n", - "Input Mug quantity: 1\n", - "Input Hat quantity: 3\n", - "Input Book quantity: 4\n", + "Input T-shirts quantity: 4\n", + "Input Mug quantity: 3\n", + "Input Hat quantity: 2\n", + "Input Book quantity: 1\n", "Input Keychain quantity: 5\n" ] } @@ -117,14 +117,14 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'T-shirt': 2, 'Mug': 1, 'Hat': 3, 'Book': 4, 'Keychain': 5}\n" + "{'T-shirt': 4, 'Mug': 3, 'Hat': 2, 'Book': 1, 'Keychain': 5}\n" ] } ], @@ -141,7 +141,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -157,15 +157,15 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ - "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain hat\n", "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain mug\n", + "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain hat\n", "Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain book\n" ] }, @@ -181,14 +181,14 @@ "Item1 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", "Item2 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", "Item3 = input(\"Please chose up to 3 of these products: t-shirt , mug, hat, book, keychain\").title()\n", - "if Item1 and Item2 and Item3 in products:\n", + "if Item1 in products and Item2 in products and Item3 in products:\n", " customer_orders.update([Item1,Item2,Item3])\n", " print(\"Successe\")" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -204,7 +204,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -230,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -248,7 +248,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -278,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -304,7 +304,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ @@ -314,7 +314,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ @@ -335,14 +335,14 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "dict_items([('T-shirt', 2), ('Mug', -1), ('Hat', 1), ('Book', 2), ('Keychain', 5)])\n" + "dict_items([('T-shirt', 4), ('Mug', 3), ('Hat', 2), ('Book', 1), ('Keychain', 5)])\n" ] } ], @@ -353,14 +353,14 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "dict_items([('T-shirt', 2), ('Mug', -1), ('Hat', 1), ('Book', 2), ('Keychain', 5)])\n" + "dict_items([('T-shirt', 4), ('Mug', 2), ('Hat', 1), ('Book', 0), ('Keychain', 5)])\n" ] } ], @@ -369,6 +369,28 @@ "print(inventory.items())" ] }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "T-shirt: 4\n", + "Mug: 2\n", + "Hat: 1\n", + "Book: 0\n", + "Keychain: 5\n" + ] + } + ], + "source": [ + "for product, qty in inventory.items():\n", + " print(f\"{product}: {qty}\")" + ] + }, { "cell_type": "code", "execution_count": null,