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 0000000..cafc993 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,449 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Lab | Data Structures " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 1: Working with Lists" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Imagine you are building a program for a teacher who wants to track the progress of their students throughout the semester. The teacher wants to input the grades of each student one by one, and get a summary of their performance. There are in total 5 students. You are tasked with building the program that will allow the teacher to do this easily.\n", + "\n", + "The program will prompt the teacher to enter the grades of each student. Once the teacher has entered all the grades, the program will calculate the total sum of the grades and display it on the screen. Then, the program will create a new list by selecting only the grades of the first, third, and fifth students entered by the teacher, and sort them in ascending order.\n", + "\n", + "Finally, the program will print out the new list, along with its length and the number of occurrences of the score 5 in the list. This will give the teacher a good overview of the performance of the selected students, and help them identify any potential issues early on." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Hint:*\n", + "- You can use the input() function to ask the user to enter their information.\n", + "- Look for list methods to perform the tasks. \n", + "- Remember, it is possible to get a part of the sequence using:\n", + "\n", + " ```python\n", + " sequence[x:y:z]\n", + " ```\n", + " where x, y, z are integers.\n", + "\n", + " The above returns a new sequence with the following characteristics:\n", + "\n", + " - A sequence with the same type as the original (a slice of a list is a list, a slice of a tuple is a tuple, and a slice of a string is a string).\n", + " - A sequence with elements from `sequence [x]` to `sequence [y-1]` (does not include a sequence [y]). By skipping `z` elements each time, it can be omitted if ` z = 1`.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Recommended External Resources:*\n", + "- *[Python Lists](https://www.w3schools.com/python/python_lists.asp)*\n", + "- *[Python List Methods](https://www.w3schools.com/python/python_ref_list.asp)*\n", + "- *[Python Built-in Functions](https://docs.python.org/3/library/functions.html)*\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please introduce strudent #1 grade 5\n", + "Please introduce strudent #2 grade 2\n", + "Please introduce strudent #3 grade 6\n", + "Please introduce strudent #4 grade 3\n", + "Please introduce strudent #5 grade 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The total sum of the grades is 21\n", + "\n", + "1st, 3rd and 5th grades sorted: [5, 5, 6]\n", + "new list contains 3 grades\n", + "there are 2 grades equal to 5\n" + ] + } + ], + "source": [ + "# Your code here\n", + "grades = []\n", + "for i in range(1, 6):\n", + " grades.append(int(input(f\"Please introduce strudent #{i} grade\")))\n", + "\n", + "\n", + "print(f\"The total sum of the grades is {sum(grades)}\")\n", + "\n", + "grades_sel = [grades[0], grades[2], grades[4]]\n", + "grades_sel.sort()\n", + "print(\"\\n1st, 3rd and 5th grades sorted: \", grades_sel)\n", + "print(f\"new list contains {len(grades_sel)} grades\")\n", + "print(f\"there are {grades_sel.count(5)} grades equal to 5\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 2: Tuples" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Imagine you're running a fruit stand and want to keep track of your inventory. Write a Python program that does the following:\n", + "\n", + "- Initializes a tuple with 5 different types of fruit.\n", + "- Outputs the first and last elements of the tuple, so you can see the full range of fruits the store offers.\n", + "- Replaces the second element of the tuple with a new fruit that the store has recently received, and prints the updated tuple so you can see the changes.\n", + "- Concatenates a new tuple containing 2 additional fruits to the original tuple, so you can add them to the store inventory, and prints the resulting tuple to see the updated inventory.\n", + "- Splits the resulting tuple into 2 tuples of 3 elements each (the first tuple contains the first 3 elements, and the second tuple contains the last 3 elements), so you can organize the inventory more effectively.\n", + "- Combines the 2 tuples from the previous step with the original tuple into a new tuple, and prints the resulting tuple and its length, so you can see the final inventory after all the changes." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Recommended External Resources: [Python Tuples Examples and Methods](https://www.w3schools.com/python/python_tuples.asp)*\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('apple', 'banana', 'grape', 'pear', 'pineapple')\n", + "First fruit is apple and last one is pineapple\n", + "('apple', 'coconut', 'grape', 'pear', 'pineapple')\n", + "('apple', 'coconut', 'grape', 'pear', 'pineapple', 'orange', 'peach')\n", + "('apple', 'coconut', 'grape') ('pineapple', 'orange', 'peach')\n", + "The final tuple of fruits is ('apple', 'coconut', 'grape', 'pineapple', 'orange', 'peach') with a length of 6\n" + ] + } + ], + "source": [ + "# Your code here\n", + "# Initializes a tuple with 5 different types of fruit.\n", + "fruits = (\"apple\", \"banana\", \"grape\", \"pear\", \"pineapple\")\n", + "print(fruits)\n", + "\n", + "# Outputs the first and last elements of the tuple, so you can see the full range of fruits the store offers.\n", + "print(f\"First fruit is {fruits[0]} and last one is {fruits[-1]}\")\n", + "\n", + "# Replaces the second element of the tuple with a new fruit that the store has recently received, and prints the updated tuple so you can see the changes.\n", + "fruits = list(fruits)\n", + "fruits[1] = \"coconut\"\n", + "fruits = tuple(fruits)\n", + "print(fruits)\n", + "\n", + "# Concatenates a new tuple containing 2 additional fruits to the original tuple, so you can add them to the store inventory, and prints the resulting tuple to see the updated inventory.\n", + "new_fruits = (\"orange\", \"peach\")\n", + "fruits = tuple(list(fruits) + list(new_fruits))\n", + "print(fruits)\n", + "\n", + "# Splits the resulting tuple into 2 tuples of 3 elements each (the first tuple contains the first 3 elements, and the second tuple contains the last 3 elements), so you can organize the inventory more effectively.\n", + "fruits_1 = fruits[:3]\n", + "fruits_2 = fruits[4:]\n", + "print(fruits_1, fruits_2)\n", + "\n", + "# Combines the 2 tuples from the previous step with the original tuple into a new tuple, and prints the resulting tuple and its length, so you can see the final inventory after all the changes.\n", + "new_fruits_2 = tuple(list(fruits_1) + list(fruits_2))\n", + "print(f\"The final tuple of fruits is {new_fruits_2} with a length of {len(new_fruits_2)}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 3: Sets" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Imagine you are a data analyst working for a literature museum. Your manager has given you two poems to analyze, and she wants you to write a Python program to extract useful information from them.\n", + "\n", + "Your program should:\n", + "\n", + "- Create two sets, one for each poem, containing all unique words in both poems (ignoring case and punctuation).\n", + "- Print the number of unique words in each set.\n", + "- Identify and print the unique words present in the first poem but not in the second one.\n", + "- Identify and print the unique words present in the second poem but not in the first one.\n", + "- Identify and print the unique words present in both poems and print it in alphabetical order." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Recommended External Resources:*\n", + "- *[Python Sets](https://www.w3schools.com/python/python_sets.asp)* \n", + "- *[Python Set Methods](https://www.w3schools.com/python/python_ref_set.asp)*\n", + "- *[Python String Methods](https://www.w3schools.com/python/python_ref_string.asp)*\n" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "poem = \"\"\"Some say the world will end in fire,\n", + "Some say in ice.\n", + "From what I’ve tasted of desire\n", + "I hold with those who favor fire.\n", + "But if it had to perish twice,\n", + "I think I know enough of hate\n", + "To say that for destruction ice\n", + "Is also great\n", + "And would suffice.\"\"\"\n", + "\n", + "new_poem = \"\"\"Some say life is but a dream,\n", + "Some say it's a test.\n", + "From what I've seen and what I deem,\n", + "I side with those who see it as a quest.\n", + "\n", + "But if it had to end today,\n", + "I think I know enough of love,\n", + "To say that though it fades away,\n", + "It's still what we are made of.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Words in poem:\n", + " {'firebut', 'greatand', 'say', 'that', 'would', 'what', 'who', 'to', 'suffice', 'had', 'world', 'firesome', 'icefrom', 'twicei', 'end', 'i', 'for', 'tasted', 'favor', 'enough', 'in', 'hateto', 'will', 'it', 'the', 'perish', 'iceis', 'know', 'if', 'of', 'i’ve', 'desirei', 'some', 'think', 'also', 'destruction', 'hold', 'those', 'with'}\n", + "Words in new_poem:\n", + " {'testfrom', 'say', 'that', 'ive', 'though', 'what', 'who', 'fades', 'see', 'to', 'had', 'its', 'end', 'i', 'awayits', 'todayi', 'dreamsome', 'enough', 'made', 'still', 'and', 'it', 'is', 'know', 'life', 'if', 'of', 'we', 'but', 'are', 'some', 'think', 'questbut', 'loveto', 'seen', 'deemi', 'side', 'as', 'those', 'a', 'with'}\n", + "\n", + "There are 39 in the first set of words\n", + "There are 41 in the second set of words\n", + "\n", + "Uniquie words in the first set not present in the second one: ['firebut', 'greatand', 'would', 'suffice', 'world', 'firesome', 'icefrom', 'twicei', 'for', 'tasted', 'favor', 'in', 'hateto', 'will', 'the', 'perish', 'iceis', 'i’ve', 'desirei', 'also', 'destruction', 'hold']\n", + "Uniquie words in the second set not present in the first one: ['testfrom', 'ive', 'though', 'fades', 'see', 'its', 'awayits', 'todayi', 'dreamsome', 'made', 'still', 'and', 'is', 'life', 'we', 'but', 'are', 'questbut', 'loveto', 'seen', 'deemi', 'side', 'as', 'a']\n", + "Uniquie words present in both sets: ['end', 'enough', 'had', 'i', 'if', 'it', 'know', 'of', 'say', 'some', 'that', 'think', 'those', 'to', 'what', 'who', 'with']\n" + ] + } + ], + "source": [ + "# Your code here\n", + "import string\n", + "def get_words(text):\n", + " exclude = set(string.punctuation)\n", + " exclude.add('\\n')\n", + " tmp = ''.join(ch for ch in text if ch not in exclude)\n", + " tmp = tmp.lower()\n", + " return set(tmp.split())\n", + "\n", + "# Create two sets, one for each poem, containing all unique words in both poems (ignoring case and punctuation).\n", + "words = get_words(poem)\n", + "words2 = get_words(new_poem)\n", + "\n", + "print(\"Words in poem:\\n\", words)\n", + "print(\"Words in new_poem:\\n\", words2)\n", + "\n", + "# Print the number of unique words in each set.\n", + "print(f\"\\nThere are {len(words)} in the first set of words\")\n", + "print(f\"There are {len(words2)} in the second set of words\")\n", + "\n", + "# Identify and print the unique words present in the first poem but not in the second one.\n", + "print(f\"\\nUniquie words in the first set not present in the second one: \", [word for word in words if not word in words2])\n", + "\n", + "# Identify and print the unique words present in the second poem but not in the first one.\n", + "print(f\"Uniquie words in the second set not present in the first one: \", [word for word in words2 if not word in words])\n", + "\n", + "# Identify and print the unique words present in both poems and print it in alphabetical order.\n", + "print(f\"Uniquie words present in both sets: \", sorted([word for word in words if word in words2]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 4: Dictionaries" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Consider the following dictionary of students with their scores in different subjects. One of the students, Bob, has complained about his score in Philosophy and, after reviewing it, the teacher has decided to update his score to 100. Write a Python program that updates Bob's score in Philosophy to 100 in the dictionary." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Recommended External Resources: [Python Dictionary Examples and Methods](https://www.w3schools.com/python/python_dictionaries.asp)*\n" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "grades = {'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}, 'Bob': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}}" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}, 'Bob': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 100}}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "grades[\"Bob\"][\"Philosophy\"] = 100\n", + "print(grades)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bonus" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Below are the two lists. Write a Python program to convert them into a dictionary in a way that item from list1 is the key and item from list2 is the value." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Hint: Use the zip() function. This function takes two or more iterables (like list, dict, string), aggregates them in a tuple, and returns it. Afterwards, you can use a function that turns a tuple into a dictionary.*" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Recommended External Resources: [Python Zip Function](https://www.w3schools.com/python/ref_func_zip.asp)*\n" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [], + "source": [ + "keys = ['Physics', 'Math', 'Chemistry', 'Philosophy']\n", + "values = [75, 85, 60,90]\n", + "\n", + "# Your code here\n", + "grades_zip = dict(zip(keys, values))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Get the subject with the minimum score from the previous dictionary." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Hint: Use the built-in function min(). Read about the parameter key.*" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "*Recommended External Resources:*\n", + "- *[Python Min Function Official Documentation](https://docs.python.org/3.8/library/functions.html#min)*\n", + "- *[How to use key function in max and min in Python](https://medium.com/analytics-vidhya/how-to-use-key-function-in-max-and-min-in-python-1fdbd661c59c)*" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Chemistry'" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code here\n", + "min(grades_zip, key=grades_zip.get)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "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.13.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 8ba652c..cafc993 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -57,11 +57,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please introduce strudent #1 grade 5\n", + "Please introduce strudent #2 grade 2\n", + "Please introduce strudent #3 grade 6\n", + "Please introduce strudent #4 grade 3\n", + "Please introduce strudent #5 grade 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The total sum of the grades is 21\n", + "\n", + "1st, 3rd and 5th grades sorted: [5, 5, 6]\n", + "new list contains 3 grades\n", + "there are 2 grades equal to 5\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "grades = []\n", + "for i in range(1, 6):\n", + " grades.append(int(input(f\"Please introduce strudent #{i} grade\")))\n", + "\n", + "\n", + "print(f\"The total sum of the grades is {sum(grades)}\")\n", + "\n", + "grades_sel = [grades[0], grades[2], grades[4]]\n", + "grades_sel.sort()\n", + "print(\"\\n1st, 3rd and 5th grades sorted: \", grades_sel)\n", + "print(f\"new list contains {len(grades_sel)} grades\")\n", + "print(f\"there are {grades_sel.count(5)} grades equal to 5\")" ] }, { @@ -95,11 +130,50 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('apple', 'banana', 'grape', 'pear', 'pineapple')\n", + "First fruit is apple and last one is pineapple\n", + "('apple', 'coconut', 'grape', 'pear', 'pineapple')\n", + "('apple', 'coconut', 'grape', 'pear', 'pineapple', 'orange', 'peach')\n", + "('apple', 'coconut', 'grape') ('pineapple', 'orange', 'peach')\n", + "The final tuple of fruits is ('apple', 'coconut', 'grape', 'pineapple', 'orange', 'peach') with a length of 6\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "# Initializes a tuple with 5 different types of fruit.\n", + "fruits = (\"apple\", \"banana\", \"grape\", \"pear\", \"pineapple\")\n", + "print(fruits)\n", + "\n", + "# Outputs the first and last elements of the tuple, so you can see the full range of fruits the store offers.\n", + "print(f\"First fruit is {fruits[0]} and last one is {fruits[-1]}\")\n", + "\n", + "# Replaces the second element of the tuple with a new fruit that the store has recently received, and prints the updated tuple so you can see the changes.\n", + "fruits = list(fruits)\n", + "fruits[1] = \"coconut\"\n", + "fruits = tuple(fruits)\n", + "print(fruits)\n", + "\n", + "# Concatenates a new tuple containing 2 additional fruits to the original tuple, so you can add them to the store inventory, and prints the resulting tuple to see the updated inventory.\n", + "new_fruits = (\"orange\", \"peach\")\n", + "fruits = tuple(list(fruits) + list(new_fruits))\n", + "print(fruits)\n", + "\n", + "# Splits the resulting tuple into 2 tuples of 3 elements each (the first tuple contains the first 3 elements, and the second tuple contains the last 3 elements), so you can organize the inventory more effectively.\n", + "fruits_1 = fruits[:3]\n", + "fruits_2 = fruits[4:]\n", + "print(fruits_1, fruits_2)\n", + "\n", + "# Combines the 2 tuples from the previous step with the original tuple into a new tuple, and prints the resulting tuple and its length, so you can see the final inventory after all the changes.\n", + "new_fruits_2 = tuple(list(fruits_1) + list(fruits_2))\n", + "print(f\"The final tuple of fruits is {new_fruits_2} with a length of {len(new_fruits_2)}\")" ] }, { @@ -136,7 +210,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -163,11 +237,56 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Words in poem:\n", + " {'firebut', 'greatand', 'say', 'that', 'would', 'what', 'who', 'to', 'suffice', 'had', 'world', 'firesome', 'icefrom', 'twicei', 'end', 'i', 'for', 'tasted', 'favor', 'enough', 'in', 'hateto', 'will', 'it', 'the', 'perish', 'iceis', 'know', 'if', 'of', 'i’ve', 'desirei', 'some', 'think', 'also', 'destruction', 'hold', 'those', 'with'}\n", + "Words in new_poem:\n", + " {'testfrom', 'say', 'that', 'ive', 'though', 'what', 'who', 'fades', 'see', 'to', 'had', 'its', 'end', 'i', 'awayits', 'todayi', 'dreamsome', 'enough', 'made', 'still', 'and', 'it', 'is', 'know', 'life', 'if', 'of', 'we', 'but', 'are', 'some', 'think', 'questbut', 'loveto', 'seen', 'deemi', 'side', 'as', 'those', 'a', 'with'}\n", + "\n", + "There are 39 in the first set of words\n", + "There are 41 in the second set of words\n", + "\n", + "Uniquie words in the first set not present in the second one: ['firebut', 'greatand', 'would', 'suffice', 'world', 'firesome', 'icefrom', 'twicei', 'for', 'tasted', 'favor', 'in', 'hateto', 'will', 'the', 'perish', 'iceis', 'i’ve', 'desirei', 'also', 'destruction', 'hold']\n", + "Uniquie words in the second set not present in the first one: ['testfrom', 'ive', 'though', 'fades', 'see', 'its', 'awayits', 'todayi', 'dreamsome', 'made', 'still', 'and', 'is', 'life', 'we', 'but', 'are', 'questbut', 'loveto', 'seen', 'deemi', 'side', 'as', 'a']\n", + "Uniquie words present in both sets: ['end', 'enough', 'had', 'i', 'if', 'it', 'know', 'of', 'say', 'some', 'that', 'think', 'those', 'to', 'what', 'who', 'with']\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "import string\n", + "def get_words(text):\n", + " exclude = set(string.punctuation)\n", + " exclude.add('\\n')\n", + " tmp = ''.join(ch for ch in text if ch not in exclude)\n", + " tmp = tmp.lower()\n", + " return set(tmp.split())\n", + "\n", + "# Create two sets, one for each poem, containing all unique words in both poems (ignoring case and punctuation).\n", + "words = get_words(poem)\n", + "words2 = get_words(new_poem)\n", + "\n", + "print(\"Words in poem:\\n\", words)\n", + "print(\"Words in new_poem:\\n\", words2)\n", + "\n", + "# Print the number of unique words in each set.\n", + "print(f\"\\nThere are {len(words)} in the first set of words\")\n", + "print(f\"There are {len(words2)} in the second set of words\")\n", + "\n", + "# Identify and print the unique words present in the first poem but not in the second one.\n", + "print(f\"\\nUniquie words in the first set not present in the second one: \", [word for word in words if not word in words2])\n", + "\n", + "# Identify and print the unique words present in the second poem but not in the first one.\n", + "print(f\"Uniquie words in the second set not present in the first one: \", [word for word in words2 if not word in words])\n", + "\n", + "# Identify and print the unique words present in both poems and print it in alphabetical order.\n", + "print(f\"Uniquie words present in both sets: \", sorted([word for word in words if word in words2]))" ] }, { @@ -193,7 +312,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ @@ -202,11 +321,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}, 'Bob': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 100}}\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "grades[\"Bob\"][\"Philosophy\"] = 100\n", + "print(grades)" ] }, { @@ -239,14 +368,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, "outputs": [], "source": [ "keys = ['Physics', 'Math', 'Chemistry', 'Philosophy']\n", "values = [75, 85, 60,90]\n", "\n", - "# Your code here" + "# Your code here\n", + "grades_zip = dict(zip(keys, values))" ] }, { @@ -275,11 +405,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Chemistry'" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "min(grades_zip, key=grades_zip.get)" ] } ], @@ -299,7 +441,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.0" } }, "nbformat": 4,