Skip to content
Open
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
183 changes: 155 additions & 28 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'Durante un tiempo no estuvo segura de si su marido era su marido.'"
]
},
"execution_count": 1,
"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) + \".\""
]
},
{
Expand All @@ -50,12 +62,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n"
]
},
{
"data": {
"text/plain": [
"'Grocery List: bananas, bread, brownie mix, broccoli.'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n",
"# Your code here:\n"
"# Your code here:\n",
"print(food_list)\n",
"check = 'B'\n",
"food_list_a = [i for i in food_list if i[0].lower() == check.lower()]\n",
"food_list_b = [j.lower() for j in food_list_a]\n",
"\"Grocery List: \"+', '.join(food_list_b) + \".\""
]
},
{
Expand All @@ -69,9 +104,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The area of the circle with radius: 4.5 is: 127.24 \n"
]
}
],
"source": [
"import math\n",
"\n",
Expand All @@ -88,6 +131,13 @@
" # Sample Output: 78.53981633\n",
" \n",
" # Your code here:\n",
" import math\n",
"string1 = \"The area of the circle with radius:\"\n",
"string2 = \"is:\"\n",
"radius = 4.5\n",
"radius_x2=radius**2\n",
"pi =round(math.pi,4)\n",
"print(f\"{string1} {radius} {string2} {round(radius_x2*pi,2)*2} \")\n",
" \n",
" \n",
"# Your output string here:"
Expand All @@ -106,9 +156,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire,\\nSome', 'say', 'in', 'ice.\\nFrom', 'what', 'I’ve', 'tasted', 'of', 'desire\\nI', 'hold', 'with', 'those', 'who', 'favor', 'fire.\\nBut', 'if', 'it', 'had', 'to', 'perish', 'twice,\\nI', 'think', 'I', 'know', 'enough', 'of', 'hate\\nTo', 'say', 'that', 'for', 'destruction', 'ice\\nIs', 'also', 'great\\nAnd', 'would', 'suffice.']\n",
"[('Some', 1), ('say', 3), ('the', 1), ('world', 1), ('will', 1), ('end', 1), ('in', 2), ('fire,\\nSome', 1), ('say', 3), ('in', 2), ('ice.\\nFrom', 1), ('what', 1), ('I’ve', 1), ('tasted', 1), ('of', 2), ('desire\\nI', 1), ('hold', 1), ('with', 1), ('those', 1), ('who', 1), ('favor', 1), ('fire.\\nBut', 1), ('if', 1), ('it', 1), ('had', 1), ('to', 1), ('perish', 1), ('twice,\\nI', 1), ('think', 1), ('I', 1), ('know', 1), ('enough', 1), ('of', 2), ('hate\\nTo', 1), ('say', 3), ('that', 1), ('for', 1), ('destruction', 1), ('ice\\nIs', 1), ('also', 1), ('great\\nAnd', 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 +179,13 @@
"Is also great\n",
"And would suffice.\"\"\"\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"poem_1= poem.split(\" \")\n",
"print(poem_1)\n",
"frequency = []\n",
"for w in poem_1:\n",
" frequency.append(poem_1.count(w))\n",
"print(str(list(zip(poem_1, frequency))))"
]
},
{
Expand All @@ -132,13 +197,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['as', 'a']\n"
]
}
],
"source": [
"blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n",
"\n",
"poem = \"\"\"I was angry with my friend; \n",
"poem2 = \"\"\"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",
Expand All @@ -158,7 +231,15 @@
"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 = [word.strip(\" ;:,.\") for word in poem2.lower().split()]\n",
"words_not_appear_in_blacklist_from_poem = []\n",
"\n",
"for i in blacklist:\n",
" if i not in poem2:\n",
" words_not_appear_in_blacklist_from_poem.append(i)\n",
"print(words_not_appear_in_blacklist_from_poem)"
]
},
{
Expand All @@ -172,14 +253,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['T', 'P']\n"
]
}
],
"source": [
"poem = \"\"\"The apparition of these faces in the crowd;\n",
"poem3 = \"\"\"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",
"import re\n",
"\n",
"uppercase_letters = re.findall('[A-Z]', poem3)\n",
"\n",
"print(uppercase_letters)"
]
},
{
Expand All @@ -191,13 +285,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['123abc', 'abc123', 'JohnSmith1', 'ABBY4']"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"filtered = [x for x in data if re.search('\\d', x) is not None]\n",
"filtered\n"
]
},
{
Expand All @@ -213,18 +320,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['123abc', 'abc123', 'JohnSmith1']"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"# Your code here:\n"
"# Your code here:\n",
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"[x for x in data if re.search(\"(?=.*\\d)(?=.*[a-z]).*\", x) is not None]\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 @@ -238,9 +365,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}