diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index c574eba..2b0a341 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -33,12 +33,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Durante un tiempo no estuvo segura de si su marido era su marido'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "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", + "x = \" \"\n", + "\n", + "sentence = \" \".join(str_list)\n", + "\n", + "sentence\n" ] }, { @@ -50,12 +66,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Grocery list: bananas,chocolate,bread,diapers,ice cream,brownie mix,broccoli'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", - "# Your code here:\n" + "new_food_list = []\n", + "# Your code here:\n", + "for item in food_list:\n", + " new_food_list.append(item.lower())\n", + "\n", + "Grocery_list = \"Grocery list: \"+ \",\".join(new_food_list)\n", + "\n", + "Grocery_list" ] }, { @@ -69,9 +103,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'The area of the circle with radius: 4.5 is: 63.61725123519331'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import math\n", "\n", @@ -90,7 +135,9 @@ " # Your code here:\n", " return pi * (x**2)\n", " \n", - "# Your output string here:\n" + "# Your output string here:\n", + "\n", + "f'{string1} {radius} {string2} {area(radius)}'" ] }, { @@ -106,9 +153,61 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'Some': 2,\n", + " 'say': 3,\n", + " 'the': 1,\n", + " 'world': 1,\n", + " 'will': 1,\n", + " 'end': 1,\n", + " 'in': 2,\n", + " 'fire': 2,\n", + " 'ice': 2,\n", + " 'From': 1,\n", + " 'what': 1,\n", + " 'I’ve': 1,\n", + " 'tasted': 1,\n", + " 'of': 2,\n", + " 'desire': 1,\n", + " 'I': 3,\n", + " 'hold': 1,\n", + " 'with': 1,\n", + " 'those': 1,\n", + " 'who': 1,\n", + " 'favor': 1,\n", + " 'But': 1,\n", + " 'if': 1,\n", + " 'it': 1,\n", + " 'had': 1,\n", + " 'to': 1,\n", + " 'perish': 1,\n", + " 'twice': 1,\n", + " 'think': 1,\n", + " 'know': 1,\n", + " 'enough': 1,\n", + " 'hate': 1,\n", + " 'To': 1,\n", + " 'that': 1,\n", + " 'for': 1,\n", + " 'destruction': 1,\n", + " 'Is': 1,\n", + " 'also': 1,\n", + " 'great': 1,\n", + " 'And': 1,\n", + " 'would': 1,\n", + " 'suffice': 1}" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "poem = \"\"\"Some say the world will end in fire,\n", "Some say in ice.\n", @@ -120,7 +219,20 @@ "Is also great\n", "And would suffice.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "\n", + "list_poem = poem.split()\n", + "dict_poem = {}\n", + "\n", + "list_poem2 = [item.strip(',.') for item in list_poem]\n", + "\n", + "for item in list_poem2:\n", + " if item in dict_poem:\n", + " dict_poem[item] += 1\n", + " else:\n", + " dict_poem[item] = 1\n", + "dict_poem\n", + "\n" ] }, { @@ -132,9 +244,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'&',\n", + " 'angry',\n", + " 'apple',\n", + " 'beheld',\n", + " 'beneath',\n", + " 'bore',\n", + " 'both',\n", + " 'bright',\n", + " 'day',\n", + " 'deceitful',\n", + " 'did',\n", + " 'end',\n", + " 'fears',\n", + " 'foe',\n", + " 'friend',\n", + " 'garden',\n", + " 'glad',\n", + " 'grew',\n", + " 'grow',\n", + " 'had',\n", + " 'he',\n", + " 'i',\n", + " 'into',\n", + " 'knew',\n", + " 'mine',\n", + " 'morning',\n", + " 'my',\n", + " 'night',\n", + " 'not',\n", + " 'outstretched',\n", + " 'pole',\n", + " 'see',\n", + " 'shine',\n", + " 'smiles',\n", + " 'soft',\n", + " 'stole',\n", + " 'sunned',\n", + " 'tears',\n", + " 'that',\n", + " 'till',\n", + " 'told',\n", + " 'tree',\n", + " 'veild',\n", + " 'was',\n", + " 'waterd',\n", + " 'when',\n", + " 'wiles',\n", + " 'with',\n", + " 'wrath'}" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n", "\n", @@ -158,7 +329,18 @@ "In the morning glad I see; \n", "My foe outstretched beneath the tree.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "\n", + "poem2 = [item.strip(',.;:') for item in poem.split()]\n", + "\n", + "poem3 = [item.lower() for item in poem2]\n", + "\n", + "words_poem = set(poem3)\n", + "black_list = set(blacklist)\n", + "\n", + "remaining_words = words_poem.difference(black_list)\n", + "\n", + "remaining_words\n" ] }, { @@ -172,16 +354,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['T', 'P']" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], "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", + "\n", + "re.findall('[A-Z]', poem)\n" ] }, { @@ -193,13 +388,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['123abc', 'abc123', 'JohnSmith1', 'ABBY4']\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "data2 = []\n", + "for item in data:\n", + " x = re.search(r'\\d', item)\n", + " if x:\n", + " data2.append(item)\n", + "print(data2)\n" ] }, { @@ -220,7 +429,8 @@ "outputs": [], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", - "# Your code here:\n" + "# Your code here:\n", + "data=\n" ] } ], diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 6873bd2..9060680 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": 2, "metadata": {}, "outputs": [], "source": [ @@ -88,11 +88,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ - "# Write your code here\n" + "# Write your code here\n", + "import numpy as np\n", + "import pandas as pd\n", + "corpus = []\n", + "for item in docs:\n", + " content = open(item, \"r\")\n", + " corpus.append(content.read())\n", + " content.close()\n" ] }, { @@ -104,10 +111,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "corpus" + ] }, { "cell_type": "markdown", @@ -132,11 +152,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['ironhack is cool', 'i love ironhack', 'i am a student at ironhack']" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Write your code here" + "# Write your code here\n", + "\n", + "corpus = [corpus[item].lower().strip(\".\") for item in range(len(corpus))]\n", + "corpus" ] }, { @@ -148,10 +182,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "bag_of_words = []" + ] }, { "cell_type": "markdown", @@ -166,11 +202,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['ironhack', 'is', 'cool', 'i', 'love', 'am', 'a', 'student', 'at']" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Write your code here\n" + "# Write your code here\n", + "for item in corpus:\n", + " for item2 in item.split():\n", + " if item2 not in bag_of_words:\n", + " bag_of_words.append(item2)\n" ] }, { @@ -186,10 +237,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "['ironhack', 'is', 'cool', 'i', 'love', 'am', 'a', 'student', 'at']" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bag_of_words" + ] }, { "cell_type": "markdown", @@ -200,11 +264,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 1, 1, 0, 0, 0, 0, 0, 0],\n", + " [1, 0, 0, 1, 1, 0, 0, 0, 0],\n", + " [1, 0, 0, 1, 0, 1, 1, 1, 1]]" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Write your code here\n" + "# Write your code here\n", + "term_freq = []\n", + "x=0\n", + "for item in corpus:\n", + " term_freq.append([])\n", + " for item2 in bag_of_words:\n", + " if item2 in item.split():\n", + " term_freq[x].append(1) \n", + " else:\n", + " term_freq[x].append(0)\n", + " x+=1\n", + "\n", + "\n", + "\n" ] }, { @@ -218,10 +308,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 1, 1, 0, 0, 0, 0, 0, 0],\n", + " [1, 0, 0, 1, 1, 0, 0, 0, 0],\n", + " [1, 0, 0, 1, 0, 1, 1, 1, 1]]" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "term_freq" + ] }, { "cell_type": "markdown", @@ -256,13 +361,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 1, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1]]" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "stop_words = ['all', 'six', 'less', 'being', 'indeed', 'over', 'move', 'anyway', 'fifty', 'four', 'not', 'own', 'through', 'yourselves', 'go', 'where', 'mill', 'only', 'find', 'before', 'one', 'whose', 'system', 'how', 'somewhere', 'with', 'thick', 'show', 'had', 'enough', 'should', 'to', 'must', 'whom', 'seeming', 'under', 'ours', 'has', 'might', 'thereafter', 'latterly', 'do', 'them', 'his', 'around', 'than', 'get', 'very', 'de', 'none', 'cannot', 'every', 'whether', 'they', 'front', 'during', 'thus', 'now', 'him', 'nor', 'name', 'several', 'hereafter', 'always', 'who', 'cry', 'whither', 'this', 'someone', 'either', 'each', 'become', 'thereupon', 'sometime', 'side', 'two', 'therein', 'twelve', 'because', 'often', 'ten', 'our', 'eg', 'some', 'back', 'up', 'namely', 'towards', 'are', 'further', 'beyond', 'ourselves', 'yet', 'out', 'even', 'will', 'what', 'still', 'for', 'bottom', 'mine', 'since', 'please', 'forty', 'per', 'its', 'everything', 'behind', 'un', 'above', 'between', 'it', 'neither', 'seemed', 'ever', 'across', 'she', 'somehow', 'be', 'we', 'full', 'never', 'sixty', 'however', 'here', 'otherwise', 'were', 'whereupon', 'nowhere', 'although', 'found', 'alone', 're', 'along', 'fifteen', 'by', 'both', 'about', 'last', 'would', 'anything', 'via', 'many', 'could', 'thence', 'put', 'against', 'keep', 'etc', 'amount', 'became', 'ltd', 'hence', 'onto', 'or', 'con', 'among', 'already', 'co', 'afterwards', 'formerly', 'within', 'seems', 'into', 'others', 'while', 'whatever', 'except', 'down', 'hers', 'everyone', 'done', 'least', 'another', 'whoever', 'moreover', 'couldnt', 'throughout', 'anyhow', 'yourself', 'three', 'from', 'her', 'few', 'together', 'top', 'there', 'due', 'been', 'next', 'anyone', 'eleven', 'much', 'call', 'therefore', 'interest', 'then', 'thru', 'themselves', 'hundred', 'was', 'sincere', 'empty', 'more', 'himself', 'elsewhere', 'mostly', 'on', 'fire', 'am', 'becoming', 'hereby', 'amongst', 'else', 'part', 'everywhere', 'too', 'herself', 'former', 'those', 'he', 'me', 'myself', 'made', 'twenty', 'these', 'bill', 'cant', 'us', 'until', 'besides', 'nevertheless', 'below', 'anywhere', 'nine', 'can', 'of', 'your', 'toward', 'my', 'something', 'and', 'whereafter', 'whenever', 'give', 'almost', 'wherever', 'is', 'describe', 'beforehand', 'herein', 'an', 'as', 'itself', 'at', 'have', 'in', 'seem', 'whence', 'ie', 'any', 'fill', 'again', 'hasnt', 'inc', 'thereby', 'thin', 'no', 'perhaps', 'latter', 'meanwhile', 'when', 'detail', 'same', 'wherein', 'beside', 'also', 'that', 'other', 'take', 'which', 'becomes', 'you', 'if', 'nobody', 'see', 'though', 'may', 'after', 'upon', 'most', 'hereupon', 'eight', 'but', 'serious', 'nothing', 'such', 'why', 'a', 'off', 'whereby', 'third', 'i', 'whole', 'noone', 'sometimes', 'well', 'amoungst', 'yours', 'their', 'rather', 'without', 'so', 'five', 'the', 'first', 'whereas', 'once']\n", "\n", - "# Write your code below\n" + "# Write your code below\n", + "\n", + "term_freq = []\n", + "x=0\n", + "for item in stop_words:\n", + " if item in bag_of_words:\n", + " bag_of_words.remove(item)\n", + "\n", + "for item in corpus:\n", + " term_freq.append([])\n", + " for item2 in bag_of_words:\n", + " if item2 in item.split():\n", + " term_freq[x].append(1) \n", + " else:\n", + " term_freq[x].append(0)\n", + " x+=1\n", + "\n", + "term_freq" ] }, { @@ -318,7 +451,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.11.2" } }, "nbformat": 4,