Skip to content

[lab-string-operations]TarineeMeesters #223

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 2 commits 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
178 changes: 142 additions & 36 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,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"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"
"combine_str_list = \" \".join(str_list)+\".\"\n",
"print (combine_str_list)\n"
]
},
{
Expand All @@ -50,12 +59,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 48,
"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 = []\n",
"for item in food_list:\n",
" if item.lower()[0] == 'b':\n",
" Grocery_list.append(item.lower())\n",
" \n",
"print(\"Grocery_list\", (Grocery_list),\".\")\n",
"\n"
]
},
{
Expand All @@ -69,9 +93,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"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 @@ -80,17 +112,13 @@
"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",
" return pi * (x**2)\n",
" \n",
"# Your output string here:\n"
"\n",
"output_string = f\"{string1} {radius} {string2} {area(radius)}\"\n",
"\n",
"print(output_string)\n",
"\n",
"\n"
]
},
{
Expand All @@ -106,9 +134,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 'suffice.': {'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': 2, 'perish': 1, 'twice,': 1, 'think': 1, 'know': 1, 'enough': 1, 'hate': 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",
Expand All @@ -120,7 +156,18 @@
"Is also great\n",
"And would suffice.\"\"\"\n",
"\n",
"# Your code here:\n"
"\n",
"list = poem.split()\n",
"\n",
"count_words = {}\n",
"for words in list:\n",
" words = words.lower()\n",
" count_words[words] = count_words.get(words, 0) +1\n",
"print(f\" '{words}': {count_words}\")\n",
" \n",
" \n",
" \n",
" "
]
},
{
Expand All @@ -132,9 +179,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'i': 1, 'was': 1, 'angry': 1, 'with': 1, 'my': 1, 'friend': 1, 'told': 1, 'wrath': 1, 'did': 1, 'end': 1, 'foe': 1, 'not': 1, 'grow': 1, 'waterd': 1, 'fears': 1, 'night': 1, 'morning': 1, 'tears': 1, 'sunned': 1, 'smiles': 1, 'soft': 1, 'deceitful': 1, 'wiles': 1, 'grew': 1, 'both': 1, 'day': 1, 'till': 1, 'bore': 1, 'apple': 1, 'bright': 1, 'beheld': 1, 'shine': 1, 'he': 1, 'knew': 1, 'that': 1, 'mine': 1, 'into': 1, 'garden': 1, 'stole': 1, 'when': 1, 'had': 1, 'veild': 1, 'pole': 1, 'glad': 1, 'see': 1, 'outstretched': 1, 'beneath': 1, 'tree': 1}\n"
]
}
],
"source": [
"blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n",
"\n",
Expand All @@ -158,7 +213,19 @@
"In the morning glad I see; \n",
"My foe outstretched beneath the tree.\"\"\"\n",
"\n",
"# Your code here:\n"
"\n",
"import re\n",
"lower_case_poem = poem.lower()\n",
"words = re.findall(r'\\b\\w+\\b', lower_case_poem)\n",
"check_with_blacklist = {}\n",
"\n",
"for item in words:\n",
" if item not in blacklist:\n",
" check_with_blacklist[item] = 1\n",
" \n",
"print(check_with_blacklist)\n",
" \n",
" \n"
]
},
{
Expand All @@ -172,16 +239,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"THE APPARITION OF THESE FACES IN THE CROWD;\n",
"PETALS ON A WET, BLACK BOUGH.\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"
"upper_case_poem = poem.upper()\n",
"\n",
"print (upper_case_poem)\n"
]
},
{
Expand All @@ -193,13 +271,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 40,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n"
]
}
],
"source": [
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"\n",
"# Your code here:\n"
"\n",
"lookup = str(data)\n",
"filtered_list = []\n",
"for item in data:\n",
" if re.search(lookup, item) is not None:\n",
" filtered_list.append(item)\n",
"print(filtered_list)\n",
"\n",
" \n"
]
},
{
Expand All @@ -215,18 +309,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"# Your code here:\n"
"\n",
"# Your code here:\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -240,7 +346,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down
Loading