Skip to content

[lab-string-operations] Bruno Santos #210

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
254 changes: 232 additions & 22 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'Durante un tiempo no estuvo segura de si su marido era su marido'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n",
"# Your code here:\n"
"# Your code here:\n",
"x = \" \"\n",
"\n",
"sentence = \" \".join(str_list)\n",
"\n",
"sentence\n"
]
},
{
Expand All @@ -50,12 +66,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'Grocery list: bananas,chocolate,bread,diapers,ice cream,brownie mix,broccoli'"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n",
"# Your code here:\n"
"new_food_list = []\n",
"# Your code here:\n",
"for item in food_list:\n",
" new_food_list.append(item.lower())\n",
"\n",
"Grocery_list = \"Grocery list: \"+ \",\".join(new_food_list)\n",
"\n",
"Grocery_list"
]
},
{
Expand All @@ -69,9 +103,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'The area of the circle with radius: 4.5 is: 63.61725123519331'"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import math\n",
"\n",
Expand All @@ -90,7 +135,9 @@
" # Your code here:\n",
" return pi * (x**2)\n",
" \n",
"# Your output string here:\n"
"# Your output string here:\n",
"\n",
"f'{string1} {radius} {string2} {area(radius)}'"
]
},
{
Expand All @@ -106,9 +153,61 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 33,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'Some': 2,\n",
" 'say': 3,\n",
" 'the': 1,\n",
" 'world': 1,\n",
" 'will': 1,\n",
" 'end': 1,\n",
" 'in': 2,\n",
" 'fire': 2,\n",
" 'ice': 2,\n",
" 'From': 1,\n",
" 'what': 1,\n",
" 'I’ve': 1,\n",
" 'tasted': 1,\n",
" 'of': 2,\n",
" 'desire': 1,\n",
" 'I': 3,\n",
" 'hold': 1,\n",
" 'with': 1,\n",
" 'those': 1,\n",
" 'who': 1,\n",
" 'favor': 1,\n",
" 'But': 1,\n",
" 'if': 1,\n",
" 'it': 1,\n",
" 'had': 1,\n",
" 'to': 1,\n",
" 'perish': 1,\n",
" 'twice': 1,\n",
" 'think': 1,\n",
" 'know': 1,\n",
" 'enough': 1,\n",
" 'hate': 1,\n",
" 'To': 1,\n",
" 'that': 1,\n",
" 'for': 1,\n",
" 'destruction': 1,\n",
" 'Is': 1,\n",
" 'also': 1,\n",
" 'great': 1,\n",
" 'And': 1,\n",
" 'would': 1,\n",
" 'suffice': 1}"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"poem = \"\"\"Some say the world will end in fire,\n",
"Some say in ice.\n",
Expand All @@ -120,7 +219,20 @@
"Is also great\n",
"And would suffice.\"\"\"\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"\n",
"list_poem = poem.split()\n",
"dict_poem = {}\n",
"\n",
"list_poem2 = [item.strip(',.') for item in list_poem]\n",
"\n",
"for item in list_poem2:\n",
" if item in dict_poem:\n",
" dict_poem[item] += 1\n",
" else:\n",
" dict_poem[item] = 1\n",
"dict_poem\n",
"\n"
]
},
{
Expand All @@ -132,9 +244,68 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 41,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'&',\n",
" 'angry',\n",
" 'apple',\n",
" 'beheld',\n",
" 'beneath',\n",
" 'bore',\n",
" 'both',\n",
" 'bright',\n",
" 'day',\n",
" 'deceitful',\n",
" 'did',\n",
" 'end',\n",
" 'fears',\n",
" 'foe',\n",
" 'friend',\n",
" 'garden',\n",
" 'glad',\n",
" 'grew',\n",
" 'grow',\n",
" 'had',\n",
" 'he',\n",
" 'i',\n",
" 'into',\n",
" 'knew',\n",
" 'mine',\n",
" 'morning',\n",
" 'my',\n",
" 'night',\n",
" 'not',\n",
" 'outstretched',\n",
" 'pole',\n",
" 'see',\n",
" 'shine',\n",
" 'smiles',\n",
" 'soft',\n",
" 'stole',\n",
" 'sunned',\n",
" 'tears',\n",
" 'that',\n",
" 'till',\n",
" 'told',\n",
" 'tree',\n",
" 'veild',\n",
" 'was',\n",
" 'waterd',\n",
" 'when',\n",
" 'wiles',\n",
" 'with',\n",
" 'wrath'}"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n",
"\n",
Expand All @@ -158,7 +329,18 @@
"In the morning glad I see; \n",
"My foe outstretched beneath the tree.\"\"\"\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"\n",
"poem2 = [item.strip(',.;:') for item in poem.split()]\n",
"\n",
"poem3 = [item.lower() for item in poem2]\n",
"\n",
"words_poem = set(poem3)\n",
"black_list = set(blacklist)\n",
"\n",
"remaining_words = words_poem.difference(black_list)\n",
"\n",
"remaining_words\n"
]
},
{
Expand All @@ -172,16 +354,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 44,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['T', 'P']"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import re\n",
"\n",
"poem = \"\"\"The apparition of these faces in the crowd;\n",
"Petals on a wet, black bough.\"\"\"\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"\n",
"re.findall('[A-Z]', poem)\n"
]
},
{
Expand All @@ -193,13 +388,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 74,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['123abc', 'abc123', 'JohnSmith1', 'ABBY4']\n"
]
}
],
"source": [
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"data2 = []\n",
"for item in data:\n",
" x = re.search(r'\\d', item)\n",
" if x:\n",
" data2.append(item)\n",
"print(data2)\n"
]
},
{
Expand All @@ -220,7 +429,8 @@
"outputs": [],
"source": [
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"# Your code here:\n"
"# Your code here:\n",
"data=\n"
]
}
],
Expand Down
Loading