From 7fb3769de98ab9cf6e37b1b5e606f9f7392bc5c2 Mon Sep 17 00:00:00 2001 From: Jesus Escamilla Date: Tue, 22 Jun 2021 15:28:44 -0500 Subject: [PATCH 1/5] solved --- .../challenge-1-checkpoint.ipynb | 421 ++++++++++++++++++ your-code/challenge-1.ipynb | 219 ++++++++- 2 files changed, 618 insertions(+), 22 deletions(-) create mode 100644 your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb diff --git a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb new file mode 100644 index 0000000..10178f0 --- /dev/null +++ b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb @@ -0,0 +1,421 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# String Operations Lab\n", + "\n", + "**Before your start:**\n", + "\n", + "- Read the README.md file\n", + "- Comment as much as you can and use the resources in the README.md file\n", + "- Happy learning!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import re" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Challenge 1 - Combining Strings\n", + "\n", + "Combining strings is an important skill to acquire. There are multiple ways of combining strings in Python, as well as combining strings with variables. We will explore this in the first challenge. In the cell below, combine the strings in the list and add spaces between the strings (do not add a space after the last string). Insert a period after the last string." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Durante un tiempo no estuvo segura de si su marido era su marido.'" + ] + }, + "execution_count": 12, + "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", + "\n", + "(\" \".join(str_list)) + '.'\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the cell below, use the list of strings to create a grocery list. Start the list with the string `Grocery list: ` and include a comma and a space between each item except for the last one. Include a period at the end. Only include foods in the list that start with the letter 'b' and ensure all foods are lower case." + ] + }, + { + "cell_type": "code", + "execution_count": 167, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['bananas', 'chocolate', 'bread', 'diapers', 'ice cream', 'brownie mix', 'broccoli']\n", + "['bananas', 'bread', 'brownie mix', 'broccoli']\n" + ] + } + ], + "source": [ + "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", + "lfood_list=[]\n", + "bfood_list=[]\n", + "# Your code here:\n", + "for i in food_list:\n", + " lfood_list.append(i.lower())\n", + "print(lfood_list)\n", + "for i in lfood_list:\n", + " if i.startswith('b'):\n", + " bfood_list.append(i)\n", + " \n", + " \n", + " \n", + "print(bfood_list)\n", + " \n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the cell below, write a function that computes the area of a circle using its radius. Compute the area of the circle and insert the radius and the area between the two strings. Make sure to include spaces between the variable and the strings. \n", + "\n", + "Note: You can use the techniques we have learned so far or use f-strings. F-strings allow us to embed code inside strings. You can read more about f-strings [here](https://www.python.org/dev/peps/pep-0498/)." + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the radius of a circle: 5\n" + ] + }, + { + "data": { + "text/plain": [ + "'The area of the circle with radius: 5, is: 21.99'" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import math\n", + "\n", + "string1 = \"The area of the circle with radius:\"\n", + "string2 = \"is:\"\n", + "radius = 4.5\n", + "\n", + "def area(x, pi = math.pi):\n", + " # This function takes a radius and returns the area of a circle. We also pass a default value for pi.\n", + " # Input: Float (and default value for pi)\n", + " # Output: Float\n", + " \n", + " # Sample input: 5.0\n", + " # Sample Output: 78.53981633\n", + " \n", + " # Your code here:\n", + " \n", + " import math\n", + "\n", + "string1 = \"The area of the circle with radius: \"\n", + "string2 = \"is: \"\n", + "\n", + "def area(radius, pi = math.pi):\n", + " area = round(pi*(radius^2), 2)\n", + " return(string1 + str(radius) + \", \" + string2 + \" \" + str(area))\n", + "\n", + "radius = int(input('Enter the radius of a circle: '))\n", + "\n", + "area(radius, pi = math.pi)\n", + "\n", + "# Your output string here:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Challenge 2 - Splitting Strings\n", + "\n", + "We have first looked at combining strings into one long string. There are times where we need to do the opposite and split the string into smaller components for further analysis. \n", + "\n", + "In the cell below, split the string into a list of strings using the space delimiter. Count the frequency of each word in the string in a dictionary. Strip the periods, line breaks and commas from the text. Make sure to remove empty strings from your dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Palabras y su frecuencia\n", + "{'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", + "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", + "# Your code here:\n", + "listapoem=(poem.split())\n", + "\n", + "frecuenciap =[]\n", + "for i in listapoem:\n", + " frecuenciap.append(listapoem.count(i))\n", + "\n", + "print(\"Palabras y su frecuencia\\n\" + str(dict(zip(listapoem, frecuenciap))))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the cell below, find all the words that appear in the text and do not appear in the blacklist. You must parse the string but can choose any data structure you wish for the words that do not appear in the blacklist. Remove all non letter characters and convert all words to lower case." + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'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": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n", + "\n", + "poem = \"\"\"I was angry with my friend; \n", + "I told my wrath, my wrath did end.\n", + "I was angry with my foe: \n", + "I told it not, my wrath did grow. \n", + "\n", + "And I waterd it in fears,\n", + "Night & morning with my tears: \n", + "And I sunned it with smiles,\n", + "And with soft deceitful wiles. \n", + "\n", + "And it grew both day and night. \n", + "Till it bore an apple bright. \n", + "And my foe beheld it shine,\n", + "And he knew that it was mine. \n", + "\n", + "And into my garden stole, \n", + "When the night had veild the pole; \n", + "In the morning glad I see; \n", + "My foe outstretched beneath the tree.\"\"\"\n", + "\n", + "# Your code here:\n", + "import re\n", + "blacklist2=set(blacklist)\n", + "poem.lower()\n", + "poem1 = re.sub(r'[^\\w\\s]','',poem.lower())\n", + "poem1.split()\n", + "poemset=set(poem1.split())\n", + "poemset.difference(blacklist2)\n", + " \n", + " \n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Challenge 3 - Regular Expressions\n", + "\n", + "Sometimes, we would like to perform more complex manipulations of our string. This is where regular expressions come in handy. In the cell below, return all characters that are upper case from the string specified below." + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['T', 'P']\n" + ] + } + ], + "source": [ + "poem = \"\"\"The apparition of these faces in the crowd;\n", + "Petals on a wet, black bough.\"\"\"\n", + "\n", + "# Your code here:\n", + "import re\n", + "print(re.findall(r'[A-Z]',poem))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the cell below, filter the list provided and return all elements of the list containing a number. To filter the list, use the `re.search` function. Check if the function does not return `None`. You can read more about the `re.search` function [here](https://docs.python.org/3/library/re.html)." + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "123abc, abc123, JohnSmith1, ABBY4, JANE\n", + "\n" + ] + } + ], + "source": [ + "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", + "\n", + "# Your code here:\n", + "import re\n", + "strdata = \", \".join(data)\n", + "print(strdata)\n", + "print(re.search(r'\\d',strdata))\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Bonus Challenge - Regular Expressions II\n", + "\n", + "In the cell below, filter the list provided to keep only strings containing at least one digit and at least one lower case letter. As in the previous question, use the `re.search` function and check that the result is not `None`.\n", + "\n", + "To read more about regular expressions, check out [this link](https://developers.google.com/edu/python/regular-expressions)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", + "# Your code here:\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.9.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 4302084..10178f0 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -33,12 +33,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Durante un tiempo no estuvo segura de si su marido era su marido.'" + ] + }, + "execution_count": 12, + "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", + "\n", + "(\" \".join(str_list)) + '.'\n" ] }, { @@ -50,12 +63,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 167, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['bananas', 'chocolate', 'bread', 'diapers', 'ice cream', 'brownie mix', 'broccoli']\n", + "['bananas', 'bread', 'brownie mix', 'broccoli']\n" + ] + } + ], "source": [ "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", - "# Your code here:\n" + "lfood_list=[]\n", + "bfood_list=[]\n", + "# Your code here:\n", + "for i in food_list:\n", + " lfood_list.append(i.lower())\n", + "print(lfood_list)\n", + "for i in lfood_list:\n", + " if i.startswith('b'):\n", + " bfood_list.append(i)\n", + " \n", + " \n", + " \n", + "print(bfood_list)\n", + " \n", + "\n", + "\n" ] }, { @@ -69,9 +106,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the radius of a circle: 5\n" + ] + }, + { + "data": { + "text/plain": [ + "'The area of the circle with radius: 5, is: 21.99'" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import math\n", "\n", @@ -89,7 +144,19 @@ " \n", " # Your code here:\n", " \n", - " \n", + " import math\n", + "\n", + "string1 = \"The area of the circle with radius: \"\n", + "string2 = \"is: \"\n", + "\n", + "def area(radius, pi = math.pi):\n", + " area = round(pi*(radius^2), 2)\n", + " return(string1 + str(radius) + \", \" + string2 + \" \" + str(area))\n", + "\n", + "radius = int(input('Enter the radius of a circle: '))\n", + "\n", + "area(radius, pi = math.pi)\n", + "\n", "# Your output string here:" ] }, @@ -106,9 +173,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Palabras y su frecuencia\n", + "{'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", @@ -120,7 +196,14 @@ "Is also great\n", "And would suffice.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "listapoem=(poem.split())\n", + "\n", + "frecuenciap =[]\n", + "for i in listapoem:\n", + " frecuenciap.append(listapoem.count(i))\n", + "\n", + "print(\"Palabras y su frecuencia\\n\" + str(dict(zip(listapoem, frecuenciap))))" ] }, { @@ -132,9 +215,67 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 131, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'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": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n", "\n", @@ -158,7 +299,17 @@ "In the morning glad I see; \n", "My foe outstretched beneath the tree.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "import re\n", + "blacklist2=set(blacklist)\n", + "poem.lower()\n", + "poem1 = re.sub(r'[^\\w\\s]','',poem.lower())\n", + "poem1.split()\n", + "poemset=set(poem1.split())\n", + "poemset.difference(blacklist2)\n", + " \n", + " \n", + " " ] }, { @@ -172,14 +323,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['T', 'P']\n" + ] + } + ], "source": [ "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", + "import re\n", + "print(re.findall(r'[A-Z]',poem))" ] }, { @@ -191,13 +352,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 159, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "123abc, abc123, JohnSmith1, ABBY4, JANE\n", + "\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "import re\n", + "strdata = \", \".join(data)\n", + "print(strdata)\n", + "print(re.search(r'\\d',strdata))\n", + "\n" ] }, { @@ -238,7 +413,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.4" } }, "nbformat": 4, From bcf7a234f642b1fa8c5846ff8ddd6458183fad22 Mon Sep 17 00:00:00 2001 From: Jesus Escamilla Date: Tue, 22 Jun 2021 16:32:37 -0500 Subject: [PATCH 2/5] solved --- .../challenge-1-checkpoint.ipynb | 64 ++----------------- your-code/challenge-1.ipynb | 64 ++----------------- your-code/challenge-2.ipynb | 2 +- 3 files changed, 15 insertions(+), 115 deletions(-) diff --git a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb index 10178f0..3c9b376 100644 --- a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb @@ -215,65 +215,15 @@ }, { "cell_type": "code", - "execution_count": 131, + "execution_count": 1, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "{'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": 131, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "{'waterd', 'both', 'i', 'with', 'day', 'deceitful', 'soft', 'grow', 'end', 'friend', 'told', 'glad', 'see', 'he', 'my', 'garden', 'had', 'till', 'fears', 'beheld', 'into', 'outstretched', 'beneath', 'tree', 'night', 'bore', 'was', 'wrath', 'veild', 'that', 'foe', 'smiles', 'wiles', 'not', 'mine', 'knew', 'stole', 'apple', 'did', 'tears', 'grew', 'when', 'pole', 'shine', 'sunned', 'angry', 'morning', 'bright'}\n" + ] } ], "source": [ @@ -306,7 +256,7 @@ "poem1 = re.sub(r'[^\\w\\s]','',poem.lower())\n", "poem1.split()\n", "poemset=set(poem1.split())\n", - "poemset.difference(blacklist2)\n", + "print(poemset.difference(blacklist2))\n", " \n", " \n", " " diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 10178f0..3c9b376 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -215,65 +215,15 @@ }, { "cell_type": "code", - "execution_count": 131, + "execution_count": 1, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "{'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": 131, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "{'waterd', 'both', 'i', 'with', 'day', 'deceitful', 'soft', 'grow', 'end', 'friend', 'told', 'glad', 'see', 'he', 'my', 'garden', 'had', 'till', 'fears', 'beheld', 'into', 'outstretched', 'beneath', 'tree', 'night', 'bore', 'was', 'wrath', 'veild', 'that', 'foe', 'smiles', 'wiles', 'not', 'mine', 'knew', 'stole', 'apple', 'did', 'tears', 'grew', 'when', 'pole', 'shine', 'sunned', 'angry', 'morning', 'bright'}\n" + ] } ], "source": [ @@ -306,7 +256,7 @@ "poem1 = re.sub(r'[^\\w\\s]','',poem.lower())\n", "poem1.split()\n", "poemset=set(poem1.split())\n", - "poemset.difference(blacklist2)\n", + "print(poemset.difference(blacklist2))\n", " \n", " \n", " " diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index d76069e..32d458e 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -323,7 +323,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.9.4" } }, "nbformat": 4, From 7abb686f6442f9a8db8459a7ca4b0b85f3c5dee7 Mon Sep 17 00:00:00 2001 From: Jesus Escamilla Date: Tue, 22 Jun 2021 19:48:47 -0500 Subject: [PATCH 3/5] solved --- .../challenge-1-checkpoint.ipynb | 31 ++++++++++++++++++- your-code/challenge-1.ipynb | 31 ++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb index 3c9b376..4d71b93 100644 --- a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb @@ -82,7 +82,7 @@ "# Your code here:\n", "for i in food_list:\n", " lfood_list.append(i.lower())\n", - "print(lfood_list)\n", + "\n", "for i in lfood_list:\n", " if i.startswith('b'):\n", " bfood_list.append(i)\n", @@ -95,6 +95,35 @@ "\n" ] }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Grocery list: bananas, bread, brownie mix, broccoli.'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", + "lfood_list=[]\n", + "bfood_list=[]\n", + "# Your code here:\n", + "for i in food_list:\n", + " lfood_list.append(i.lower())\n", + "for i in lfood_list:\n", + " if i[0] == 'b':\n", + " bfood_list.append(i)\n", + "'Grocery list: ' + (', '.join(bfood_list)) + '.'\n" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 3c9b376..4d71b93 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -82,7 +82,7 @@ "# Your code here:\n", "for i in food_list:\n", " lfood_list.append(i.lower())\n", - "print(lfood_list)\n", + "\n", "for i in lfood_list:\n", " if i.startswith('b'):\n", " bfood_list.append(i)\n", @@ -95,6 +95,35 @@ "\n" ] }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Grocery list: bananas, bread, brownie mix, broccoli.'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", + "lfood_list=[]\n", + "bfood_list=[]\n", + "# Your code here:\n", + "for i in food_list:\n", + " lfood_list.append(i.lower())\n", + "for i in lfood_list:\n", + " if i[0] == 'b':\n", + " bfood_list.append(i)\n", + "'Grocery list: ' + (', '.join(bfood_list)) + '.'\n" + ] + }, { "cell_type": "markdown", "metadata": {}, From 0a03d3f91c6fd765f8c124cfbb2306b2851f17cd Mon Sep 17 00:00:00 2001 From: Jesus Escamilla Date: Wed, 23 Jun 2021 01:46:52 -0500 Subject: [PATCH 4/5] solved --- .../challenge-2-checkpoint.ipynb | 110 ++++++++++++++---- your-code/challenge-1.ipynb | 23 +++- your-code/challenge-2.ipynb | 108 +++++++++++++---- 3 files changed, 195 insertions(+), 46 deletions(-) diff --git a/your-code/.ipynb_checkpoints/challenge-2-checkpoint.ipynb b/your-code/.ipynb_checkpoints/challenge-2-checkpoint.ipynb index d76069e..0661005 100644 --- a/your-code/.ipynb_checkpoints/challenge-2-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/challenge-2-checkpoint.ipynb @@ -72,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 113, "metadata": {}, "outputs": [], "source": [ @@ -88,13 +88,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 158, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], "source": [ + "#Aqui si me salio pero lo hice uno por uno, seguro habra una forma para iterar todo mas eficiente y meterlo a la lista\n", "corpus = []\n", + "with open(\"doc1.txt\") as fname:\n", + " lineas=fname.readlines()\n", + " for linea in lineas:\n", + " corpus.append(linea)\n", + "with open(\"doc2.txt\") as fname2:\n", + " lineas=fname2.readlines()\n", + " for linea in lineas:\n", + " corpus.append(linea)\n", + "with open(\"doc3.txt\") as fname3:\n", + " lineas=fname3.readlines()\n", + " for linea in lineas:\n", + " corpus.append(linea)\n", "\n", - "# Write your code here\n" + "\n", + "print(corpus)" ] }, { @@ -106,9 +128,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 159, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], "source": [ "print(corpus)" ] @@ -136,11 +166,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 171, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ironhack is cool i love ironhack i am a student at ironhack\n" + ] + } + ], "source": [ - "# Write your code here" + "(\" \".join(corpus).lower())\n", + "\n", + "corpus1 = re.sub(r'[^\\w\\s]','',(\" \".join(corpus).lower()))\n", + "print(corpus1)" ] }, { @@ -152,11 +193,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 186, "metadata": {}, "outputs": [], "source": [ - "bag_of_words = []" + "bag_of_words=[]\n" ] }, { @@ -172,11 +213,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 188, "metadata": {}, "outputs": [], "source": [ - "# Write your code here" + "corpus2=(corpus1.split())\n", + "for element in corpus2:\n", + " if element not in bag_of_words:\n", + " bag_of_words.append(element)\n", + "\n" ] }, { @@ -192,9 +237,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 189, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ironhack', 'is', 'cool', 'i', 'love', 'am', 'a', 'student', 'at']\n" + ] + } + ], "source": [ "print(bag_of_words)" ] @@ -208,13 +261,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 197, "metadata": {}, "outputs": [], "source": [ - "term_freq = []\n", - "\n", - "# Write your code here" + "#No logre que me saliera este\n", + "term_freq=[]\n", + "for element in bag_of_words:\n", + " term_freq.append(bag_of_words.count(element))\n", + " \n", + " \n", + "\n", + "\n" ] }, { @@ -228,9 +286,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 198, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 1, 1, 1, 1, 1, 1, 1, 1]\n" + ] + } + ], "source": [ "print(term_freq)" ] @@ -323,7 +389,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.9.4" } }, "nbformat": 4, diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 4d71b93..3c16d10 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -202,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -235,6 +235,23 @@ "print(\"Palabras y su frecuencia\\n\" + str(dict(zip(listapoem, frecuenciap))))" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire,', 'Some', 'say', 'in', 'ice.', 'From', 'what', 'I’ve', 'tasted', 'of', 'desire', 'I', 'hold', 'with', 'those', 'who', 'favor', 'fire.', 'But', 'if', 'it', 'had', 'to', 'perish', 'twice,', 'I', 'think', 'I', 'know', 'enough', 'of', 'hate', 'To', 'say', 'that', 'for', 'destruction', 'ice', 'Is', 'also', 'great', 'And', 'would', 'suffice.']\n" + ] + } + ], + "source": [ + "print(listapoem)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -244,14 +261,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'waterd', 'both', 'i', 'with', 'day', 'deceitful', 'soft', 'grow', 'end', 'friend', 'told', 'glad', 'see', 'he', 'my', 'garden', 'had', 'till', 'fears', 'beheld', 'into', 'outstretched', 'beneath', 'tree', 'night', 'bore', 'was', 'wrath', 'veild', 'that', 'foe', 'smiles', 'wiles', 'not', 'mine', 'knew', 'stole', 'apple', 'did', 'tears', 'grew', 'when', 'pole', 'shine', 'sunned', 'angry', 'morning', 'bright'}\n" + "{'till', 'not', 'stole', 'angry', 'tears', 'fears', 'glad', 'see', 'wrath', 'garden', 'grew', 'mine', 'end', 'foe', 'had', 'morning', 'bore', 'both', 'smiles', 'that', 'tree', 'night', 'soft', 'he', 'pole', 'veild', 'bright', 'apple', 'beheld', 'when', 'outstretched', 'did', 'grow', 'beneath', 'deceitful', 'was', 'sunned', 'day', 'i', 'wiles', 'with', 'told', 'knew', 'my', 'shine', 'into', 'waterd', 'friend'}\n" ] } ], diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 32d458e..0661005 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": 113, "metadata": {}, "outputs": [], "source": [ @@ -88,13 +88,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 158, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], "source": [ + "#Aqui si me salio pero lo hice uno por uno, seguro habra una forma para iterar todo mas eficiente y meterlo a la lista\n", "corpus = []\n", + "with open(\"doc1.txt\") as fname:\n", + " lineas=fname.readlines()\n", + " for linea in lineas:\n", + " corpus.append(linea)\n", + "with open(\"doc2.txt\") as fname2:\n", + " lineas=fname2.readlines()\n", + " for linea in lineas:\n", + " corpus.append(linea)\n", + "with open(\"doc3.txt\") as fname3:\n", + " lineas=fname3.readlines()\n", + " for linea in lineas:\n", + " corpus.append(linea)\n", "\n", - "# Write your code here\n" + "\n", + "print(corpus)" ] }, { @@ -106,9 +128,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 159, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], "source": [ "print(corpus)" ] @@ -136,11 +166,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 171, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ironhack is cool i love ironhack i am a student at ironhack\n" + ] + } + ], "source": [ - "# Write your code here" + "(\" \".join(corpus).lower())\n", + "\n", + "corpus1 = re.sub(r'[^\\w\\s]','',(\" \".join(corpus).lower()))\n", + "print(corpus1)" ] }, { @@ -152,11 +193,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 186, "metadata": {}, "outputs": [], "source": [ - "bag_of_words = []" + "bag_of_words=[]\n" ] }, { @@ -172,11 +213,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 188, "metadata": {}, "outputs": [], "source": [ - "# Write your code here" + "corpus2=(corpus1.split())\n", + "for element in corpus2:\n", + " if element not in bag_of_words:\n", + " bag_of_words.append(element)\n", + "\n" ] }, { @@ -192,9 +237,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 189, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ironhack', 'is', 'cool', 'i', 'love', 'am', 'a', 'student', 'at']\n" + ] + } + ], "source": [ "print(bag_of_words)" ] @@ -208,13 +261,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 197, "metadata": {}, "outputs": [], "source": [ - "term_freq = []\n", - "\n", - "# Write your code here" + "#No logre que me saliera este\n", + "term_freq=[]\n", + "for element in bag_of_words:\n", + " term_freq.append(bag_of_words.count(element))\n", + " \n", + " \n", + "\n", + "\n" ] }, { @@ -228,9 +286,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 198, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 1, 1, 1, 1, 1, 1, 1, 1]\n" + ] + } + ], "source": [ "print(term_freq)" ] From 571f6dc76d5842e0176ae3dd09a4581929dc28a4 Mon Sep 17 00:00:00 2001 From: Jesus Escamilla Date: Wed, 23 Jun 2021 10:22:43 -0500 Subject: [PATCH 5/5] solved --- .../challenge-1-checkpoint.ipynb | 42 +++++++++++++------ .../challenge-2-checkpoint.ipynb | 27 ++++++------ your-code/challenge-1.ipynb | 21 +++++----- your-code/challenge-2.ipynb | 27 ++++++------ 4 files changed, 69 insertions(+), 48 deletions(-) diff --git a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb index 4d71b93..c3950ab 100644 --- a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -202,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -235,6 +235,23 @@ "print(\"Palabras y su frecuencia\\n\" + str(dict(zip(listapoem, frecuenciap))))" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire,', 'Some', 'say', 'in', 'ice.', 'From', 'what', 'I’ve', 'tasted', 'of', 'desire', 'I', 'hold', 'with', 'those', 'who', 'favor', 'fire.', 'But', 'if', 'it', 'had', 'to', 'perish', 'twice,', 'I', 'think', 'I', 'know', 'enough', 'of', 'hate', 'To', 'say', 'that', 'for', 'destruction', 'ice', 'Is', 'also', 'great', 'And', 'would', 'suffice.']\n" + ] + } + ], + "source": [ + "print(listapoem)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -244,14 +261,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'waterd', 'both', 'i', 'with', 'day', 'deceitful', 'soft', 'grow', 'end', 'friend', 'told', 'glad', 'see', 'he', 'my', 'garden', 'had', 'till', 'fears', 'beheld', 'into', 'outstretched', 'beneath', 'tree', 'night', 'bore', 'was', 'wrath', 'veild', 'that', 'foe', 'smiles', 'wiles', 'not', 'mine', 'knew', 'stole', 'apple', 'did', 'tears', 'grew', 'when', 'pole', 'shine', 'sunned', 'angry', 'morning', 'bright'}\n" + "{'till', 'not', 'stole', 'angry', 'tears', 'fears', 'glad', 'see', 'wrath', 'garden', 'grew', 'mine', 'end', 'foe', 'had', 'morning', 'bore', 'both', 'smiles', 'that', 'tree', 'night', 'soft', 'he', 'pole', 'veild', 'bright', 'apple', 'beheld', 'when', 'outstretched', 'did', 'grow', 'beneath', 'deceitful', 'was', 'sunned', 'day', 'i', 'wiles', 'with', 'told', 'knew', 'my', 'shine', 'into', 'waterd', 'friend'}\n" ] } ], @@ -331,27 +348,26 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "123abc, abc123, JohnSmith1, ABBY4, JANE\n", - "\n" + "['123abc', 'abc123', 'JohnSmith1', 'ABBY4']\n" ] } ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", - "\n", + "data_w_numbers=[]\n", "# Your code here:\n", - "import re\n", - "strdata = \", \".join(data)\n", - "print(strdata)\n", - "print(re.search(r'\\d',strdata))\n", - "\n" + "\n", + "for i in data:\n", + " if(re.search('[0-9]+',i)):\n", + " data_w_numbers.append(i)\n", + "print(data_w_numbers)" ] }, { diff --git a/your-code/.ipynb_checkpoints/challenge-2-checkpoint.ipynb b/your-code/.ipynb_checkpoints/challenge-2-checkpoint.ipynb index 0661005..4b28acc 100644 --- a/your-code/.ipynb_checkpoints/challenge-2-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/challenge-2-checkpoint.ipynb @@ -72,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -88,7 +88,7 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -101,6 +101,7 @@ ], "source": [ "#Aqui si me salio pero lo hice uno por uno, seguro habra una forma para iterar todo mas eficiente y meterlo a la lista\n", + "import re\n", "corpus = []\n", "with open(\"doc1.txt\") as fname:\n", " lineas=fname.readlines()\n", @@ -128,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -166,7 +167,7 @@ }, { "cell_type": "code", - "execution_count": 171, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -193,7 +194,7 @@ }, { "cell_type": "code", - "execution_count": 186, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -213,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": 188, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -237,7 +238,7 @@ }, { "cell_type": "code", - "execution_count": 189, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -261,14 +262,16 @@ }, { "cell_type": "code", - "execution_count": 197, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "#No logre que me saliera este\n", "term_freq=[]\n", - "for element in bag_of_words:\n", - " term_freq.append(bag_of_words.count(element))\n", + "for element in corpus2:\n", + " for i in bag_of_words:\n", + " term_freq.append(bag_of_words.count(i))\n", + "\n", " \n", " \n", "\n", @@ -286,14 +289,14 @@ }, { "cell_type": "code", - "execution_count": 198, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[1, 1, 1, 1, 1, 1, 1, 1, 1]\n" + "[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n" ] } ], diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 3c16d10..c3950ab 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -202,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -348,27 +348,26 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "123abc, abc123, JohnSmith1, ABBY4, JANE\n", - "\n" + "['123abc', 'abc123', 'JohnSmith1', 'ABBY4']\n" ] } ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", - "\n", + "data_w_numbers=[]\n", "# Your code here:\n", - "import re\n", - "strdata = \", \".join(data)\n", - "print(strdata)\n", - "print(re.search(r'\\d',strdata))\n", - "\n" + "\n", + "for i in data:\n", + " if(re.search('[0-9]+',i)):\n", + " data_w_numbers.append(i)\n", + "print(data_w_numbers)" ] }, { diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 0661005..4b28acc 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -72,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -88,7 +88,7 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -101,6 +101,7 @@ ], "source": [ "#Aqui si me salio pero lo hice uno por uno, seguro habra una forma para iterar todo mas eficiente y meterlo a la lista\n", + "import re\n", "corpus = []\n", "with open(\"doc1.txt\") as fname:\n", " lineas=fname.readlines()\n", @@ -128,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -166,7 +167,7 @@ }, { "cell_type": "code", - "execution_count": 171, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -193,7 +194,7 @@ }, { "cell_type": "code", - "execution_count": 186, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -213,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": 188, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -237,7 +238,7 @@ }, { "cell_type": "code", - "execution_count": 189, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -261,14 +262,16 @@ }, { "cell_type": "code", - "execution_count": 197, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "#No logre que me saliera este\n", "term_freq=[]\n", - "for element in bag_of_words:\n", - " term_freq.append(bag_of_words.count(element))\n", + "for element in corpus2:\n", + " for i in bag_of_words:\n", + " term_freq.append(bag_of_words.count(i))\n", + "\n", " \n", " \n", "\n", @@ -286,14 +289,14 @@ }, { "cell_type": "code", - "execution_count": 198, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[1, 1, 1, 1, 1, 1, 1, 1, 1]\n" + "[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n" ] } ],