Skip to content

[lab-string-operations] - Letícia Graziela Demarchi Ferreira #214

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
132 changes: 106 additions & 26 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,47 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import re"
]
},
{
"attachments": {},
"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."
"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) . ( pay attention) Insert a period after the last string."
]
},
{
"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"
"\n",
"\n",
"combined_str = ' '.join(str_list[:-1]) + '.' + str_list[-1]\n",
"\n",
"print(combined_str)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -50,12 +64,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"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"
"\n",
"Grocery_list = 'Grocery list: ' + ', '.join([food.lower() for food in food_list if food.lower().startswith('b')]) + '.'\n",
"\n",
"print(Grocery_list)\n",
"\n"
]
},
{
Expand All @@ -69,9 +95,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The area of the circle with radius: 4.5 is: 63.61725123519331\n"
]
}
],
"source": [
"import math\n",
"\n",
Expand All @@ -90,7 +124,12 @@
" # Your code here:\n",
" return pi * (x**2)\n",
" \n",
"# Your output string here:\n"
"# Your output string here:\n",
"\n",
"output_str = f\"{string1} {radius} {string2} {area(radius)}\"\n",
"\n",
"print(output_str)\n",
"\n"
]
},
{
Expand All @@ -106,7 +145,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -120,7 +159,7 @@
"Is also great\n",
"And would suffice.\"\"\"\n",
"\n",
"# Your code here:\n"
"# Your code here: IDK\n"
]
},
{
Expand All @@ -132,9 +171,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"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', 'fears', 'night', 'morning', 'with', 'my', 'tears', 'i', 'sunned', 'with', 'smiles', 'with', 'soft', 'deceitful', 'wiles', 'grew', 'both', 'day', 'night', 'till', 'bore', 'apple', 'bright', 'my', 'foe', 'beheld', 'shine', '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",
Expand All @@ -158,7 +205,11 @@
"In the morning glad I see; \n",
"My foe outstretched beneath the tree.\"\"\"\n",
"\n",
"# Your code here:\n"
"poem_words = re.findall(r'\\b[a-z]+\\b', poem.lower())\n",
"blacklist_set = set(blacklist)\n",
"filtered_words = [word for word in poem_words if word not in blacklist_set]\n",
"\n",
"print(filtered_words)\n"
]
},
{
Expand All @@ -172,16 +223,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['T', 'P']\n"
]
}
],
"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"
"uppercase_chars = re.findall(r'[A-Z]', poem)\n",
"print(uppercase_chars)"
]
},
{
Expand All @@ -193,13 +253,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"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"
"result = list(filter(lambda x: re.search('\\d', x), data))\n",
"print(result)"
]
},
{
Expand All @@ -215,12 +284,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['123abc', 'abc123', 'JohnSmith1']\n"
]
}
],
"source": [
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"# Your code here:\n"
"\n",
"filtered_list = [s for s in data if re.search(r'\\d', s) and re.search(r'[a-z]', s)]\n",
"\n",
"print(filtered_list)\n"
]
}
],
Expand All @@ -240,7 +320,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.11.2"
}
},
"nbformat": 4,
Expand Down
Loading