From 8408d7bf9205b97708d8d91fc1cec98c68b558dd Mon Sep 17 00:00:00 2001 From: Fernando Carvalho Date: Fri, 21 Apr 2023 15:21:27 +0100 Subject: [PATCH] lab done --- your-code/challenge-1.ipynb | 203 ++++++++++++++++++++++++++++++------ your-code/challenge-2.ipynb | 26 +++-- 2 files changed, 194 insertions(+), 35 deletions(-) diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index c574eba..f2beecd 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -15,11 +15,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "import re" + "import re\n", + "import pandas as pd" ] }, { @@ -33,12 +34,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Durante un tiempo no estuvo segura de si su marido era su marido.\n" + ] + } + ], "source": [ "str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", - "# Your code here:\n" + "# Your code here:\n", + "new_str = \"\"\n", + "for w in str_list:\n", + " new_str = new_str +\" \"+ w \n", + "\n", + "new_str = new_str + \".\" \n", + "print(new_str)" ] }, { @@ -50,12 +65,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Grocery List: Bananas, Chocolate, bread, di apers, Ice Cream, Brownie Mix, broccoli.\n" + ] + } + ], "source": [ - "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", - "# Your code here:\n" + "food_list = ['Bananas', 'Chocolate', 'bread', 'di apers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", + "# Your code here:\n", + "new_list = \"Grocery List: \"\n", + "\n", + "for w in food_list:\n", + " if food_list[0]== w:\n", + " new_list = new_list + w \n", + " else:\n", + " new_list = new_list +\", \"+ w\n", + "new_list = new_list + \".\" \n", + "\n", + "print(new_list)" ] }, { @@ -69,9 +102,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The area of the circle with radius: 4.5 is: 78.53981633974483!\n" + ] + } + ], "source": [ "import math\n", "\n", @@ -90,7 +131,9 @@ " # Your code here:\n", " return pi * (x**2)\n", " \n", - "# Your output string here:\n" + "# Your output string here:\n", + "all_string = string1 + \" \"+ str(radius) + \" \" + string2 + \" \" + str(area(5)) + \"!\"\n", + "print(all_string)" ] }, { @@ -106,9 +149,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 164, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Some': 2, 'say': 3, 'the': 1, 'world': 1, 'will': 1, 'end': 1, 'in': 2, 'fire,': 1, 'ice.': 1, 'From': 1, 'what': 1, 'I’ve': 1, 'tasted': 1, 'of': 2, 'desire': 1, 'I': 3, 'hold': 1, 'with': 1, 'those': 1, 'who': 1, 'favor': 1, 'fire.': 1, 'But': 1, 'if': 1, 'it': 1, 'had': 1, 'to': 1, 'perish': 1, 'twice,': 1, 'think': 1, 'know': 1, 'enough': 1, 'hate': 1, 'To': 1, 'that': 1, 'for': 1, 'destruction': 1, 'ice': 1, 'Is': 1, 'also': 1, 'great': 1, 'And': 1, 'would': 1, 'suffice.': 1}\n" + ] + } + ], "source": [ "poem = \"\"\"Some say the world will end in fire,\n", "Some say in ice.\n", @@ -119,8 +170,17 @@ "To say that for destruction ice\n", "Is also great\n", "And would suffice.\"\"\"\n", + "# Your code here:\n", + "dic = dict()\n", + "list_w = str(poem).split()\n", "\n", - "# Your code here:\n" + "for item in list_w:\n", + " if item in dic:\n", + " dic[item] += 1\n", + " else:\n", + " dic[item] = 1\n", + " \n", + "print(dic)" ] }, { @@ -132,9 +192,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 192, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['i', 'was', 'angry', 'with', 'my', 'friend', 'i', 'told', 'my', 'wrath', 'my', 'wrath', 'did', 'end', 'i', 'was', 'angry', 'with', 'my', 'foe', 'i', 'told', 'not', 'my', 'wrath', 'did', 'grow', 'i', 'waterd', 'fears', 'night', '&', 'morning', 'with', 'my', 'tears', 'i', 'sunned', 'with', 'smiles', 'with', 'soft', 'deceitful', 'wiles', 'grew', 'both', 'day', 'night', 'till', 'bore', 'apple', 'bright', 'my', 'foe', 'beheld', 'shine', 'he', 'knew', 'that', 'was', 'mine', 'into', 'my', 'garden', 'stole', 'when', 'night', 'had', 'veild', 'pole', 'morning', 'glad', 'i', 'see', 'my', 'foe', 'outstretched', 'beneath', 'tree']\n" + ] + } + ], "source": [ "blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n", "\n", @@ -158,7 +226,22 @@ "In the morning glad I see; \n", "My foe outstretched beneath the tree.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "poem = poem.lower()\n", + "poem = poem.replace(\",\",\"\")\n", + "poem = poem.replace(\":\",\"\")\n", + "poem = poem.replace(\".\",\"\")\n", + "poem = poem.replace(\";\",\"\")\n", + "#print(poem)\n", + "\n", + "list_p = str(poem).split()\n", + "new_list = []\n", + "\n", + "for el in list_p:\n", + " if el not in blacklist:\n", + " new_list.append(el)\n", + " \n", + "print(new_list)" ] }, { @@ -172,16 +255,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 205, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['T', 'P']\n" + ] + } + ], "source": [ "import re\n", "\n", "poem = \"\"\"The apparition of these faces in the crowd;\n", "Petals on a wet, black bough.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "poem = poem.replace(\",\",\"\")\n", + "poem = poem.replace(\".\",\"\")\n", + "poem = poem.replace(\";\",\"\")\n", + "\n", + "list_p = str(poem).split()\n", + "upper_letters = []\n", + "\n", + "for word in list_p:\n", + " for let in word:\n", + " if let == let.upper():\n", + " upper_letters.append(let)\n", + " \n", + "print(upper_letters)" ] }, { @@ -193,13 +297,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 222, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "123abc\n", + "abc123\n", + "JohnSmith1\n", + "ABBY4\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "import re\n", + "\n", + "for el in data:\n", + " if re.search(\"1\",el) or re.search(\"4\",el):\n", + " print(el)\n", + " " ] }, { @@ -215,18 +336,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 262, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['123abc', '123abc', '123abc', 'abc123', 'abc123', 'abc123', 'JohnSmith1', 'ABBY4']\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", - "# Your code here:\n" + "# Your code here:\n", + "#remove Digits and lower case letter\n", + "new=[]\n", + "\n", + "for el in data:\n", + " for lett in el:\n", + " if lett.isdigit() == True:\n", + " new.append(el)\n", + " \n", + "print(new)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -240,7 +385,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.9.13" } }, "nbformat": 4, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 6873bd2..bef0f31 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -72,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -88,11 +88,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['doc1.txt', 'doc2.txt', 'doc3.txt']\n" + ] + } + ], "source": [ - "# Write your code here\n" + "# Write your code here\n", + "corpus = []\n", + "\n", + "for file in docs:\n", + " corpus.append(file)\n", + " \n", + "print(corpus)" ] }, { @@ -304,7 +318,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -318,7 +332,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.9.13" } }, "nbformat": 4,