Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -33,12 +33,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 33,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'Durante un tiempo no estuvo segura de si su marido era su marido.'"
]
},
"execution_count": 33,
"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"
" \n",
"' '.join(str_list)+'.'\n",
"\n"
]
},
{
Expand All @@ -50,12 +63,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 91,
"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"
"grocery_list=['Grocery list: ']\n",
"\n",
"for i in food_list:\n",
" if re.findall(r'b',i) or re.findall(r'B', i): \n",
" if i == food_list[-1]:\n",
" grocery_list.append(i+'.')\n",
" else:\n",
" grocery_list.append(i+',')\n",
" \n",
"grocery_list= ' '.join(grocery_list)\n",
"print(grocery_list.lower())"
]
},
{
Expand All @@ -69,28 +100,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 101,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'The area of the circle with radius: 4.5 is: 63.61725123519331'"
]
},
"execution_count": 101,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import math\n",
"\n",
"string1 = \"The area of the circle with radius:\"\n",
"string2 = \"is:\"\n",
"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",
"def area(x):\n",
" pi = math.pi\n",
" aerea= pi*x**2\n",
" return (f\"{string1} {radius} {string2} {aerea}\")\n",
" \n",
" \n",
"# Your output string here:"
"area(radius)\n"
]
},
{
Expand All @@ -106,9 +142,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 478,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'Some': 2, 'say': 3, 'the': 1, 'world': 1, 'will': 1, 'end': 1, 'in': 2, 'fire': 2, 'ice': 2, '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, 'But': 1, 'if': 1, 'it': 1, 'had': 1, 'to': 1, 'perish': 1, 'twice': 1, 'think': 1, 'know': 1, 'enough': 1, 'hate': 1, 'To': 1, 'that': 1, 'for': 1, 'destruction': 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 +164,10 @@
"Is also great\n",
"And would suffice.\"\"\"\n",
"\n",
"# Your code here:\n"
"poem= poem.replace(',','').replace('.','')\n",
"list_strings= poem.split()\n",
"count_strings= {word: list_strings.count(word) for word in list_strings}\n",
"print(count_strings)"
]
},
{
Expand All @@ -132,9 +179,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 479,
"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.', 'and', 'i', 'waterd', 'fears', 'night', '&', 'morning', 'with', 'my', 'tears:', 'and', 'i', 'sunned', 'with', 'smiles', 'and', 'with', 'soft', 'deceitful', 'wiles.', 'and', 'grew', 'both', 'day', 'night.', 'till', 'bore', 'apple', 'bright.', 'and', 'my', 'foe', 'beheld', 'shine', 'and', 'he', 'knew', 'that', 'was', 'mine.', 'and', 'into', 'my', 'garden', 'stole', 'when', 'night', 'had', 'veild', 'pole;', 'in', '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 +213,14 @@
"In the morning glad I see; \n",
"My foe outstretched beneath the tree.\"\"\"\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"poem= poem.replace(',','').replace(',','')\n",
"poem= poem.split()\n",
"new_poem=[word.lower() for word in poem if word not in blacklist]\n",
"\n",
"print (new_poem)\n",
"\n",
"# poem - blacklist\n"
]
},
{
Expand All @@ -172,14 +234,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 484,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['T', 'P']"
]
},
"execution_count": 484,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"poem = \"\"\"The apparition of these faces in the crowd;\n",
"Petals on a wet, black bough.\"\"\"\n",
"poem = \"\"\"The apparition of these faces in the crowd;\\nPetals on a wet, black bough.\"\"\"\n",
"\n",
"# Your code here:\n"
"a= re.findall(r'[A-Z]', poem)\n",
"([i for i in poem if i in a])\n"
]
},
{
Expand All @@ -191,13 +264,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 482,
"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"
"lista= [i for i in data if re.search('\\d',i)]\n",
"print(lista)\n",
"del lista"
]
},
{
Expand All @@ -213,18 +296,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 510,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['123abc', 'abc123', 'JohnSmith1']\n"
]
}
],
"source": [
"import random\n",
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"# Your code here:\n"
"lista= [i for i in data if re.search('\\d',i) and re.search('[a-z]',i)]\n",
"\n",
"print (lista)\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -238,7 +333,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.10.3"
}
},
"nbformat": 4,
Expand Down
Loading