From a979d519dd368d8a796e09f6692d4048627747fa Mon Sep 17 00:00:00 2001 From: MARCOS DAVID Date: Sun, 2 Oct 2022 23:54:43 -0500 Subject: [PATCH 1/4] parte1 --- your-code/challenge-1.ipynb | 109 +++++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 15 deletions(-) diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 4302084..4c430a0 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -4,6 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "\n", "# String Operations Lab\n", "\n", "**Before your start:**\n", @@ -33,12 +34,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Durante un tiempo no estuvo segura de si su marido era su marido'" + ] + }, + "execution_count": 2, + "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", + "' '.join(str_list)\n" ] }, { @@ -50,12 +63,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "bananas, chocolate, bread, diapers, ice cream, brownie mix, broccoli\n" + ] + } + ], "source": [ "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", - "# Your code here:\n" + "# Your code here:\n", + "\n", + "\"\"\"\n", + "for i in range(len(food_list)):\n", + " #print(food_list[i][0])\n", + " print(i)\n", + " letra = food_list[i][0]\n", + " print(letra)\n", + " if letra == 'b':\n", + " food_list.pop(i)\n", + " \n", + "print(food.list)\n", + "\n", + "\"\"\"\n", + "food2 = [] \n", + "food2 = ', '.join(food_list)\n", + "food2 = food2.lower()\n", + "print(type(food2))\n", + "print(food2)\n" ] }, { @@ -69,17 +109,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "78.5398163375\n", + "The area of the circle with radius: 5,is: 78.5398163375\n" + ] + } + ], "source": [ "import math\n", "\n", "string1 = \"The area of the circle with radius:\"\n", "string2 = \"is:\"\n", - "radius = 4.5\n", + "radius = 5\n", + "\n", + "def area(r):\n", + " pi=3.1415926535\n", + " r=float(r)\n", + " area2 = (pi*r*r)\n", + " return area2\n", + "\n", + "b = area(radius)\n", "\n", - "def area(x, pi = math.pi):\n", + "\n", + "frase = f'{string1} {radius},{string2} {b}'\n", + "print(frase)\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", @@ -106,9 +165,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 101, "metadata": {}, - "outputs": [], + "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", + "['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": [ "poem = \"\"\"Some say the world will end in fire,\n", "Some say in ice.\n", @@ -120,7 +188,18 @@ "Is also great\n", "And would suffice.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "\n", + "poem=poem.replace('.',' ')\n", + "poem=poem.replace('\\n',' ')\n", + "poem=poem.replace(',',' ')\n", + "print(poem)\n", + "\n", + "#poem2 = list(poem)\n", + "#print(poem2)\n", + "poem3=poem.split()\n", + "\n", + "print(poem3)" ] }, { @@ -224,7 +303,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -238,7 +317,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.12" } }, "nbformat": 4, From 6099709a873372580e341ad5494ffda64582b904 Mon Sep 17 00:00:00 2001 From: MARCOS DAVID Date: Sun, 2 Oct 2022 23:55:49 -0500 Subject: [PATCH 2/4] parte1.1 --- .../challenge-1-checkpoint.ipynb | 325 ++++++++++++++++++ 1 file changed, 325 insertions(+) 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..4c430a0 --- /dev/null +++ b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb @@ -0,0 +1,325 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "# 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": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Durante un tiempo no estuvo segura de si su marido era su marido'" + ] + }, + "execution_count": 2, + "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", + "' '.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": 51, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "bananas, chocolate, bread, diapers, ice cream, brownie mix, broccoli\n" + ] + } + ], + "source": [ + "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", + "# Your code here:\n", + "\n", + "\"\"\"\n", + "for i in range(len(food_list)):\n", + " #print(food_list[i][0])\n", + " print(i)\n", + " letra = food_list[i][0]\n", + " print(letra)\n", + " if letra == 'b':\n", + " food_list.pop(i)\n", + " \n", + "print(food.list)\n", + "\n", + "\"\"\"\n", + "food2 = [] \n", + "food2 = ', '.join(food_list)\n", + "food2 = food2.lower()\n", + "print(type(food2))\n", + "print(food2)\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": 80, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "78.5398163375\n", + "The area of the circle with radius: 5,is: 78.5398163375\n" + ] + } + ], + "source": [ + "import math\n", + "\n", + "string1 = \"The area of the circle with radius:\"\n", + "string2 = \"is:\"\n", + "radius = 5\n", + "\n", + "def area(r):\n", + " pi=3.1415926535\n", + " r=float(r)\n", + " area2 = (pi*r*r)\n", + " return area2\n", + "\n", + "b = area(radius)\n", + "\n", + "\n", + "frase = f'{string1} {radius},{string2} {b}'\n", + "print(frase)\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", + " \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": 101, + "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", + "['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": [ + "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", + "\n", + "poem=poem.replace('.',' ')\n", + "poem=poem.replace('\\n',' ')\n", + "poem=poem.replace(',',' ')\n", + "print(poem)\n", + "\n", + "#poem2 = list(poem)\n", + "#print(poem2)\n", + "poem3=poem.split()\n", + "\n", + "print(poem3)" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "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" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "poem = \"\"\"The apparition of these faces in the crowd;\n", + "Petals on a wet, black bough.\"\"\"\n", + "\n", + "# Your code here:\n" + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", + "\n", + "# Your code here:\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 (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.9.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From dbdbdee1220d7745dbe06f5eb5dabc0e56467442 Mon Sep 17 00:00:00 2001 From: MARCOS DAVID Date: Mon, 3 Oct 2022 20:02:18 -0500 Subject: [PATCH 3/4] primera parte casi resuelto --- .../challenge-1-checkpoint.ipynb | 98 ++++++++++++++++--- your-code/challenge-1.ipynb | 98 ++++++++++++++++--- 2 files changed, 166 insertions(+), 30 deletions(-) diff --git a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb index 4c430a0..857e637 100644 --- a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb @@ -34,16 +34,25 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 15, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", + "['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido', '.']\n", + "Durante un tiempo no estuvo segura de si su marido era su marido .\n" + ] + }, { "data": { "text/plain": [ - "'Durante un tiempo no estuvo segura de si su marido era su marido'" + "'Durante un tiempo no estuvo segura de si su marido era su marido.'" ] }, - "execution_count": 2, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -51,7 +60,14 @@ "source": [ "str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", "# Your code here:\n", - "' '.join(str_list)\n" + "print(str_list)\n", + "str_list.append('.')\n", + "print(str_list)\n", + "\n", + "lista2= ' '.join(str_list)\n", + "print(lista2)\n", + "\n", + "lista2.replace(' .','.')\n" ] }, { @@ -63,21 +79,49 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n", - "bananas, chocolate, bread, diapers, ice cream, brownie mix, broccoli\n" + "bananas bread brownie mix broccoli.\n", + "Lista de comestibles: bananas bread brownie mix broccoli.\n" ] + }, + { + "data": { + "text/plain": [ + "\"\\nfood2 = [] \\nfood2 = ', '.join(food_list)\\nfood2 = food2.lower()\\nprint(type(food2))\\nprint(food2)\\n\"" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", "# Your code here:\n", + "listf=[]\n", + "for i in range(len(food_list)):\n", + " lista3=food_list[i]\n", + " #print(lista3)\n", + " pregunta = lista3.lower().startswith('b')\n", + " if pregunta:\n", + " #print(lista3)\n", + " listf.append(lista3.lower())\n", + " \n", + "string1='Lista de comestibles:'\n", + "\n", + "listf.append('.')\n", + "lista2= ' '.join(listf)\n", + "lista2= lista2.replace(' .','.')\n", + "print(lista2)\n", + "\n", + "frase = f'{string1} {lista2}'\n", + "print(frase)\n", "\n", "\"\"\"\n", "for i in range(len(food_list)):\n", @@ -91,11 +135,13 @@ "print(food.list)\n", "\n", "\"\"\"\n", + "\"\"\"\n", "food2 = [] \n", "food2 = ', '.join(food_list)\n", "food2 = food2.lower()\n", "print(type(food2))\n", - "print(food2)\n" + "print(food2)\n", + "\"\"\"" ] }, { @@ -109,36 +155,45 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 65, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "78.5398163375\n", - "The area of the circle with radius: 5,is: 78.5398163375\n" + "78.53981633\n", + "The area of the circle with radius: 5,is: 78.53981634\n", + "The area of the circle with radius: 5,is: 78.53981633\n" ] } ], "source": [ "import math\n", + "#from math import floor\n", "\n", "string1 = \"The area of the circle with radius:\"\n", "string2 = \"is:\"\n", "radius = 5\n", "\n", "def area(r):\n", - " pi=3.1415926535\n", + " pi=3.1415926535897932\n", " r=float(r)\n", " area2 = (pi*r*r)\n", + " area2= round(float(area2),10)\n", " return area2\n", "\n", "b = area(radius)\n", + "b2=str(b)\n", + "print(b2[0:11])\n", "\n", + "b= format(b,'.8f')\n", "\n", "frase = f'{string1} {radius},{string2} {b}'\n", "print(frase)\n", + "\n", + "frase = f'{string1} {radius},{string2} {b2[0:11]}'\n", + "print(frase)\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", @@ -165,7 +220,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 75, "metadata": {}, "outputs": [ { @@ -173,11 +228,14 @@ "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", - "['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" + "['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", + "{'Some': 2, 'say': 3, 'the': 1, 'world': 1, 'will': 1, 'end': 1, 'in': 2, 'fire': 2, 'ice': 2, '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, '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, 'Is': 1, 'also': 1, 'great': 1, 'And': 1, 'would': 1, 'suffice': 1}\n" ] } ], "source": [ + "import re\n", + "\n", "poem = \"\"\"Some say the world will end in fire,\n", "Some say in ice.\n", "From what I’ve tasted of desire\n", @@ -199,7 +257,17 @@ "#print(poem2)\n", "poem3=poem.split()\n", "\n", - "print(poem3)" + "print(poem3)\n", + "\n", + "dic_palabra={}\n", + "\n", + "for i in range(len(poem3)):\n", + " palabra=poem3[i]\n", + " cuenta=poem3.count(palabra)\n", + " dic_palabra.setdefault(palabra,cuenta)\n", + " #print(palabra,cuenta)\n", + " \n", + "print(dic_palabra)" ] }, { diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 4c430a0..857e637 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -34,16 +34,25 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 15, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", + "['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido', '.']\n", + "Durante un tiempo no estuvo segura de si su marido era su marido .\n" + ] + }, { "data": { "text/plain": [ - "'Durante un tiempo no estuvo segura de si su marido era su marido'" + "'Durante un tiempo no estuvo segura de si su marido era su marido.'" ] }, - "execution_count": 2, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -51,7 +60,14 @@ "source": [ "str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", "# Your code here:\n", - "' '.join(str_list)\n" + "print(str_list)\n", + "str_list.append('.')\n", + "print(str_list)\n", + "\n", + "lista2= ' '.join(str_list)\n", + "print(lista2)\n", + "\n", + "lista2.replace(' .','.')\n" ] }, { @@ -63,21 +79,49 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n", - "bananas, chocolate, bread, diapers, ice cream, brownie mix, broccoli\n" + "bananas bread brownie mix broccoli.\n", + "Lista de comestibles: bananas bread brownie mix broccoli.\n" ] + }, + { + "data": { + "text/plain": [ + "\"\\nfood2 = [] \\nfood2 = ', '.join(food_list)\\nfood2 = food2.lower()\\nprint(type(food2))\\nprint(food2)\\n\"" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", "# Your code here:\n", + "listf=[]\n", + "for i in range(len(food_list)):\n", + " lista3=food_list[i]\n", + " #print(lista3)\n", + " pregunta = lista3.lower().startswith('b')\n", + " if pregunta:\n", + " #print(lista3)\n", + " listf.append(lista3.lower())\n", + " \n", + "string1='Lista de comestibles:'\n", + "\n", + "listf.append('.')\n", + "lista2= ' '.join(listf)\n", + "lista2= lista2.replace(' .','.')\n", + "print(lista2)\n", + "\n", + "frase = f'{string1} {lista2}'\n", + "print(frase)\n", "\n", "\"\"\"\n", "for i in range(len(food_list)):\n", @@ -91,11 +135,13 @@ "print(food.list)\n", "\n", "\"\"\"\n", + "\"\"\"\n", "food2 = [] \n", "food2 = ', '.join(food_list)\n", "food2 = food2.lower()\n", "print(type(food2))\n", - "print(food2)\n" + "print(food2)\n", + "\"\"\"" ] }, { @@ -109,36 +155,45 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 65, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "78.5398163375\n", - "The area of the circle with radius: 5,is: 78.5398163375\n" + "78.53981633\n", + "The area of the circle with radius: 5,is: 78.53981634\n", + "The area of the circle with radius: 5,is: 78.53981633\n" ] } ], "source": [ "import math\n", + "#from math import floor\n", "\n", "string1 = \"The area of the circle with radius:\"\n", "string2 = \"is:\"\n", "radius = 5\n", "\n", "def area(r):\n", - " pi=3.1415926535\n", + " pi=3.1415926535897932\n", " r=float(r)\n", " area2 = (pi*r*r)\n", + " area2= round(float(area2),10)\n", " return area2\n", "\n", "b = area(radius)\n", + "b2=str(b)\n", + "print(b2[0:11])\n", "\n", + "b= format(b,'.8f')\n", "\n", "frase = f'{string1} {radius},{string2} {b}'\n", "print(frase)\n", + "\n", + "frase = f'{string1} {radius},{string2} {b2[0:11]}'\n", + "print(frase)\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", @@ -165,7 +220,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 75, "metadata": {}, "outputs": [ { @@ -173,11 +228,14 @@ "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", - "['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" + "['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", + "{'Some': 2, 'say': 3, 'the': 1, 'world': 1, 'will': 1, 'end': 1, 'in': 2, 'fire': 2, 'ice': 2, '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, '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, 'Is': 1, 'also': 1, 'great': 1, 'And': 1, 'would': 1, 'suffice': 1}\n" ] } ], "source": [ + "import re\n", + "\n", "poem = \"\"\"Some say the world will end in fire,\n", "Some say in ice.\n", "From what I’ve tasted of desire\n", @@ -199,7 +257,17 @@ "#print(poem2)\n", "poem3=poem.split()\n", "\n", - "print(poem3)" + "print(poem3)\n", + "\n", + "dic_palabra={}\n", + "\n", + "for i in range(len(poem3)):\n", + " palabra=poem3[i]\n", + " cuenta=poem3.count(palabra)\n", + " dic_palabra.setdefault(palabra,cuenta)\n", + " #print(palabra,cuenta)\n", + " \n", + "print(dic_palabra)" ] }, { From f9b46c9d1327575034b7f7d664417086da35be9d Mon Sep 17 00:00:00 2001 From: MARCOS DAVID Date: Tue, 4 Oct 2022 20:24:35 -0500 Subject: [PATCH 4/4] [ADD] CAMBIO CHALLENGE 1 Y 2 --- .../challenge-1-checkpoint.ipynb | 114 +++++++-- your-code/challenge-1.ipynb | 114 +++++++-- your-code/challenge-2.ipynb | 242 ++++++++++++++++-- 3 files changed, 396 insertions(+), 74 deletions(-) diff --git a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb index 857e637..61ddfee 100644 --- a/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/challenge-1-checkpoint.ipynb @@ -34,7 +34,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 79, "metadata": {}, "outputs": [ { @@ -43,18 +43,9 @@ "text": [ "['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", "['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido', '.']\n", - "Durante un tiempo no estuvo segura de si su marido era su marido .\n" + "Durante un tiempo no estuvo segura de si su marido era su marido .\n", + "Durante un tiempo no estuvo segura de si su marido era su marido.\n" ] - }, - { - "data": { - "text/plain": [ - "'Durante un tiempo no estuvo segura de si su marido era su marido.'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ @@ -67,7 +58,11 @@ "lista2= ' '.join(str_list)\n", "print(lista2)\n", "\n", - "lista2.replace(' .','.')\n" + "lista2.replace(' .','.')\n", + "str_list2 = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", + "# Your code here:\n", + "lista3= ' '.join(str_list2)+'.'\n", + "print(lista3)" ] }, { @@ -220,15 +215,13 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 80, "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", - "['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", "{'Some': 2, 'say': 3, 'the': 1, 'world': 1, 'will': 1, 'end': 1, 'in': 2, 'fire': 2, 'ice': 2, '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, '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, 'Is': 1, 'also': 1, 'great': 1, 'And': 1, 'would': 1, 'suffice': 1}\n" ] } @@ -251,13 +244,13 @@ "poem=poem.replace('.',' ')\n", "poem=poem.replace('\\n',' ')\n", "poem=poem.replace(',',' ')\n", - "print(poem)\n", + "#print(poem)\n", "\n", "#poem2 = list(poem)\n", "#print(poem2)\n", "poem3=poem.split()\n", "\n", - "print(poem3)\n", + "#print(poem3)\n", "\n", "dic_palabra={}\n", "\n", @@ -279,12 +272,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 110, "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', 'fearsnight', '&', 'morning', 'with', 'my', 'tears', 'i', 'sunned', 'with', 'smilesand', 'with', 'soft', 'deceitful', 'wiles', 'grew', 'both', 'day', 'night', 'till', 'bore', 'apple', 'bright', 'my', 'foe', 'beheld', 'shineand', '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", + "new_list_poem = []\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", @@ -305,7 +308,25 @@ "In the morning glad I see; \n", "My foe outstretched beneath the tree.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "\n", + "poem = poem.replace('.',' ').replace('\\n','').replace(',','').replace(';','').replace(':','').lower()\n", + "\"\"\"\n", + "poem=poem.replace('.',' ')\n", + "poem=poem.replace('\\n',' ')\n", + "poem=poem.replace(',',' ')\n", + "poem=poem.replace(';',' ')\n", + "poem=poem.replace(':',' ')\n", + "\"\"\"\n", + "poem3 = poem.split()\n", + "\n", + "\n", + "for producto in poem3: #lista principal\n", + " if producto not in blacklist: #lista donde sacamos los malos\n", + " new_list_poem.append(producto) #nueva lista sin los malos\n", + "\n", + "print(new_list_poem)\n", + "\n" ] }, { @@ -319,14 +340,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 127, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "T\n", + "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", + "\n", + "for letra in poem:\n", + " may=letra.isupper()\n", + " if may:\n", + " print(letra)\n", + " \n", + " \n" ] }, { @@ -338,13 +375,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 164, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "123abc abc123 JohnSmith1 ABBY4 JANE\n", + "['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", + "['123', '123', '1', '4']\n" + ] + } + ], "source": [ + "import re\n", + "\n", "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", "\n", - "# Your code here:\n" + "data2= ' '.join(data)\n", + "\n", + "print(data2)\n", + "\n", + "# Your code here:\n", + "#re.findall(\"\\w\\S*@*.\\w\", line)\n", + "#numbers = re.findall('[0-9]+', str)\n", + "\n", + "x = re.findall('\\w*[0-9]*\\w', data2)\n", + "y = re.findall('[0-9]+', data2)\n", + "print(x)\n", + "print(y)\n" ] }, { diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 857e637..61ddfee 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -34,7 +34,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 79, "metadata": {}, "outputs": [ { @@ -43,18 +43,9 @@ "text": [ "['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", "['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido', '.']\n", - "Durante un tiempo no estuvo segura de si su marido era su marido .\n" + "Durante un tiempo no estuvo segura de si su marido era su marido .\n", + "Durante un tiempo no estuvo segura de si su marido era su marido.\n" ] - }, - { - "data": { - "text/plain": [ - "'Durante un tiempo no estuvo segura de si su marido era su marido.'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ @@ -67,7 +58,11 @@ "lista2= ' '.join(str_list)\n", "print(lista2)\n", "\n", - "lista2.replace(' .','.')\n" + "lista2.replace(' .','.')\n", + "str_list2 = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", + "# Your code here:\n", + "lista3= ' '.join(str_list2)+'.'\n", + "print(lista3)" ] }, { @@ -220,15 +215,13 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 80, "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", - "['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", "{'Some': 2, 'say': 3, 'the': 1, 'world': 1, 'will': 1, 'end': 1, 'in': 2, 'fire': 2, 'ice': 2, '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, '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, 'Is': 1, 'also': 1, 'great': 1, 'And': 1, 'would': 1, 'suffice': 1}\n" ] } @@ -251,13 +244,13 @@ "poem=poem.replace('.',' ')\n", "poem=poem.replace('\\n',' ')\n", "poem=poem.replace(',',' ')\n", - "print(poem)\n", + "#print(poem)\n", "\n", "#poem2 = list(poem)\n", "#print(poem2)\n", "poem3=poem.split()\n", "\n", - "print(poem3)\n", + "#print(poem3)\n", "\n", "dic_palabra={}\n", "\n", @@ -279,12 +272,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 110, "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', 'fearsnight', '&', 'morning', 'with', 'my', 'tears', 'i', 'sunned', 'with', 'smilesand', 'with', 'soft', 'deceitful', 'wiles', 'grew', 'both', 'day', 'night', 'till', 'bore', 'apple', 'bright', 'my', 'foe', 'beheld', 'shineand', '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", + "new_list_poem = []\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", @@ -305,7 +308,25 @@ "In the morning glad I see; \n", "My foe outstretched beneath the tree.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "\n", + "poem = poem.replace('.',' ').replace('\\n','').replace(',','').replace(';','').replace(':','').lower()\n", + "\"\"\"\n", + "poem=poem.replace('.',' ')\n", + "poem=poem.replace('\\n',' ')\n", + "poem=poem.replace(',',' ')\n", + "poem=poem.replace(';',' ')\n", + "poem=poem.replace(':',' ')\n", + "\"\"\"\n", + "poem3 = poem.split()\n", + "\n", + "\n", + "for producto in poem3: #lista principal\n", + " if producto not in blacklist: #lista donde sacamos los malos\n", + " new_list_poem.append(producto) #nueva lista sin los malos\n", + "\n", + "print(new_list_poem)\n", + "\n" ] }, { @@ -319,14 +340,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 127, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "T\n", + "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", + "\n", + "for letra in poem:\n", + " may=letra.isupper()\n", + " if may:\n", + " print(letra)\n", + " \n", + " \n" ] }, { @@ -338,13 +375,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 164, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "123abc abc123 JohnSmith1 ABBY4 JANE\n", + "['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", + "['123', '123', '1', '4']\n" + ] + } + ], "source": [ + "import re\n", + "\n", "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", "\n", - "# Your code here:\n" + "data2= ' '.join(data)\n", + "\n", + "print(data2)\n", + "\n", + "# Your code here:\n", + "#re.findall(\"\\w\\S*@*.\\w\", line)\n", + "#numbers = re.findall('[0-9]+', str)\n", + "\n", + "x = re.findall('\\w*[0-9]*\\w', data2)\n", + "y = re.findall('[0-9]+', data2)\n", + "print(x)\n", + "print(y)\n" ] }, { diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 87c5656..3a4546c 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -88,13 +88,99 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 184, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ironhack is cool.\n" + ] + }, + { + "data": { + "text/plain": [ + "'\\nfor i in docs:\\n archivo = open(i)\\n archivo.read()\\n archivo.close()\\n with open(i) as archivo:\\n data = archivo.readlines()\\n print(data)\\n'" + ] + }, + "execution_count": 184, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "corpus = []\n", - "\n", - "# Write your code here\n" + "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']\n", + "\n", + "# Write your code here\n", + "ruta_relativa = 'doc1.txt'\n", + "\n", + "archivo = open(ruta_relativa)\n", + "\n", + "data3=[]\n", + "data4=[]\n", + "\n", + "with open(ruta_relativa) as archivo:\n", + " data1 = archivo.read()\n", + " print(data1)\n", + "\n", + "archivo = open(docs[1])\n", + "\n", + "with open(docs[1]) as archivo:\n", + " data2 = archivo.read()\n", + " #print(data2)\n", + " \n", + "archivo = open(docs[2])\n", + "\n", + "with open(docs[2]) as archivo:\n", + " data3 = archivo.read()\n", + " #print(data3)\n", + " \n", + " data1 = str(data1)\n", + " data2 = str(data2)\n", + " data3 = str(data3)\n", + " \n", + "corpus.append(data1)\n", + "corpus.append(data2) \n", + "corpus.append(data3) \n", + "\n", + "\n", + "\n", + "\n", + "\"\"\"\n", + "#inteto 2 \n", + "for x in range(docs):\n", + " archivo = open(docs[x])\n", + " with open(docs[x]) as archivo:\n", + " data5.append(archivo.readlines())\n", + " \n", + "\"\"\"\n", + "\n", + "\n", + "\n", + "\"\"\"\n", + "#inteto 2\n", + "a=0\n", + "for i in docs:\n", + " archivo = open(i)\n", + " archivo.read()\n", + " archivo.close()\n", + " with open(i) as archivo:\n", + " data2[a] = archivo.readlines()\n", + " a = a+1\n", + "\"\"\"\n", + " \n", + " \n", + "\"\"\"\n", + "for i in docs:\n", + " archivo = open(i)\n", + " archivo.read()\n", + " archivo.close()\n", + " with open(i) as archivo:\n", + " data = archivo.readlines()\n", + " print(data)\n", + "\"\"\"" ] }, { @@ -106,9 +192,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 187, "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 +230,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 188, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n", + "ironhack is cool i love ironhack i am a student at ironhack \n" + ] + } + ], "source": [ - "# Write your code here" + "# Write your code here\n", + "listaN= ''.join(corpus)\n", + "print(corpus)\n", + "\n", + "listaN = listaN.replace('.',' ').replace('[','').replace(']','').replace(\"'\",'').lower()\n", + "print(listaN)\n", + "\n", + "\n", + "#listaN2='ironhack is cool i love ironhack i love ironhack '\n" ] }, { @@ -152,7 +263,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 189, "metadata": {}, "outputs": [], "source": [ @@ -172,11 +283,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 190, "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" + "# Write your code here\n", + "listaN2= ''.join(listaN)\n", + "listaN2 = listaN2.split()\n", + "print(listaN2)\n", + "\n", + "\n", + "for palabra in listaN2:\n", + " if palabra not in bag_of_words:\n", + " bag_of_words.append(palabra)\n", + "\n" ] }, { @@ -192,9 +320,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 191, "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 +344,79 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 235, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ironhack is cool.\n", + "['ironhack', 'is', 'cool', 'i', 'love', 'am', 'a', 'student', 'at']\n", + "1\n", + "ironhack ironhack is cool\n", + "is ironhack is cool\n", + "cool ironhack is cool\n", + "i ironhack is cool\n", + "love ironhack is cool\n", + "am ironhack is cool\n", + "a ironhack is cool\n", + "student ironhack is cool\n", + "at ironhack is cool\n", + "[1, 1, 1, 0, 0, 0, 1, 0, 0]\n" + ] + }, + { + "data": { + "text/plain": [ + "'\\nconteos = {}\\nciclos = 0\\nfor numero in set(lista_repetido):\\n ciclos+=1\\n conteos[numero] = lista_repetido.count(numero)\\n '" + ] + }, + "execution_count": 235, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "term_freq = []\n", "\n", - "# Write your code here" + "print(corpus[0])\n", + "print(bag_of_words)\n", + "y= 'ironhack is cool'\n", + "\n", + "conteos = y.count('ironhack')\n", + "print(conteos)\n", + "m=1\n", + "n=0\n", + "for i in bag_of_words: \n", + " x = y.count(i)\n", + " if x > m:\n", + " x=0\n", + " \n", + " term_freq.append(x)\n", + " print(i,y)\n", + "\n", + "\n", + "\"\"\"\n", + "for i in bag_of_words:\n", + " x = i.find('am')\n", + " term_freq.append(x+1)\n", + " \n", + " \"\"\"\n", + "\n", + "#term_freq = bag_of_words[5].find('am')\n", + "\n", + "\n", + "print(term_freq)\n", + "\n", + "\"\"\"\n", + "conteos = {}\n", + "ciclos = 0\n", + "for numero in set(lista_repetido):\n", + " ciclos+=1\n", + " conteos[numero] = lista_repetido.count(numero)\n", + " \"\"\"\n", + "\n" ] }, { @@ -319,7 +521,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -333,7 +535,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.9.12" } }, "nbformat": 4,