Skip to content

[lab-string-operations] Francisco Barreto #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 170 additions & 26 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -33,12 +33,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Durante un tiempo no estuvo segura de si su marido era su marido\n"
]
}
],
"source": [
"str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n",
"# Your code here:\n"
"# Your code here:\n",
"string_1 = \" \".join(str_list)\n",
"print(string_1)"
]
},
{
Expand All @@ -50,12 +60,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Grocery list :Bananas, bread, 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",
"Grocery_string = \",\".join(food_list)\n",
"rule = \"[Bb]\\\\w+\\s?\\w+\"\n",
"print(\"Grocery list :\" + \", \".join(re.findall(rule,Grocery_string)))"
]
},
{
Expand All @@ -69,19 +90,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"insert float:5\n",
"78.53981633974483\n"
]
}
],
"source": [
"import math\n",
"\n",
"string1 = \"The area of the circle with radius:\"\n",
"string2 = \"is:\"\n",
"radius = 4.5\n",
"x= float(input(\"insert float:\"))\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",
" # Input: Float (and default value for pi)\n",
"\n",
" # Output: Float\n",
" \n",
" # Sample input: 5.0\n",
Expand All @@ -90,7 +122,9 @@
" # Your code here:\n",
" return pi * (x**2)\n",
" \n",
"# Your output string here:\n"
"# Your output string here:\n",
"\n",
"print(area(x))"
]
},
{
Expand All @@ -106,9 +140,61 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"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': 4,\n",
" 've': 1,\n",
" 'tasted': 1,\n",
" 'of': 2,\n",
" 'desire': 1,\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": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"poem = \"\"\"Some say the world will end in fire,\n",
"Some say in ice.\n",
Expand All @@ -120,7 +206,16 @@
"Is also great\n",
"And would suffice.\"\"\"\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"rule = \"\\\\w+\"\n",
"poem_list= re.findall(rule,poem)\n",
"poem_list\n",
"\n",
"from collections import Counter\n",
"\n",
"word_count = dict(Counter(poem_list))\n",
"\n",
"word_count"
]
},
{
Expand All @@ -132,9 +227,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"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', 'it', 'not', 'my', 'wrath', 'did', 'grow', 'And', 'I', 'waterd', 'it', 'in', 'fears', 'Night', 'morning', 'with', 'my', 'tears', 'And', 'I', 'sunned', 'it', 'with', 'smiles', 'And', 'with', 'soft', 'deceitful', 'wiles', 'And', 'it', 'grew', 'both', 'day', 'and', 'night', 'Till', 'it', 'bore', 'an', 'apple', 'bright', 'And', 'my', 'foe', 'beheld', 'it', 'shine', 'And', 'he', 'knew', 'that', 'it', 'was', 'mine', 'And', 'into', 'my', 'garden', 'stole', 'When', 'the', 'night', 'had', 'veild', 'the', 'pole', 'In', 'the', 'morning', 'glad', 'I', 'see', 'My', 'foe', 'outstretched', 'beneath', 'the', 'tree']\n",
"i was angry with my friend i told my wrath my wrath did end i was angry with my foe i told it not my wrath did grow and i waterd it in fears night morning with my tears and i sunned it with smiles and with soft deceitful wiles and it grew both day and night till it bore an apple bright and my foe beheld it shine and he knew that it was mine and into my garden stole when the night had veild the pole in the morning glad i see my foe outstretched beneath the tree\n"
]
}
],
"source": [
"blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n",
"\n",
Expand All @@ -158,7 +262,21 @@
"In the morning glad I see; \n",
"My foe outstretched beneath the tree.\"\"\"\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"rule = \"\\\\w+\"\n",
"poem_list1= re.findall(rule,poem)\n",
"poem_list1\n",
"poem_list2 = []\n",
"for element in (blacklist,poem_list1):\n",
" if element in blacklist:\n",
" poem_list1.remove(element)\n",
"\n",
"print(poem_list1)\n",
"\n",
"poem1 = ' '.join(map(str, poem_list1))\n",
"\n",
"###------\n",
"print(poem1.lower())"
]
},
{
Expand All @@ -172,16 +290,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['The', 'Petals']"
]
},
"execution_count": 7,
"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",
"rule = \"[A-Z]\\\\w+\"\n",
"\n",
"re.findall(rule,poem)"
]
},
{
Expand All @@ -193,13 +325,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<re.Match object; span=(2, 5), match='123'>\n"
]
}
],
"source": [
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"data_s = str(data)\n",
"data_s\n",
"match = re.search(\"\\d+?\\w+?\\d+?\",data_s)\n",
"print (match)"
]
},
{
Expand All @@ -215,7 +359,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -226,7 +370,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -240,7 +384,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
Loading