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
188 changes: 148 additions & 40 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,23 @@
},
{
"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"
"# Your code here:\n",
"sep = ' '\n",
"nueva_string = sep.join(str_list) + '.'\n",
"print(nueva_string)"
]
},
{
Expand All @@ -50,14 +61,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"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"
"food_list = [food.lower() for food in food_list if food.lower().startswith('b')]\n",
"grocery_list = ', '.join(food_list)\n",
"grocery_list = \"Grocery list: \" + grocery_list + \".\"\n",
"print(grocery_list)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -69,28 +98,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"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",
"def area(radius, pi = math.pi):\n",
" return pi * (radius**2)\n",
"\n",
"string1 = \"The area of the circle with radius:\"\n",
"string2 = \"is:\"\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",
" \n",
" \n",
"# Your output string here:"
"area_of_circle = area(radius)\n",
"\n",
"print(string1 + \" \" + str(radius) + \" \" + string2 + \" \" + str(area_of_circle))"
]
},
{
Expand All @@ -106,9 +137,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"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': 4, 've': 1, 'tasted': 1, 'of': 2, 'desire': 1, '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 +159,20 @@
"Is also great\n",
"And would suffice.\"\"\"\n",
"\n",
"# Your code here:\n"
"words = re.findall(r'\\b\\w+\\b', poem)\n",
"\n",
"words = [word.strip(\".,\\n\") for word in words]\n",
"\n",
"words = list(filter(lambda x: x != \"\", words))\n",
"\n",
"word_freq = {}\n",
"for word in words:\n",
" if word in word_freq:\n",
" word_freq[word] += 1\n",
" else:\n",
" word_freq[word] = 1\n",
"\n",
"print(word_freq)"
]
},
{
Expand All @@ -132,9 +184,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"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 +218,14 @@
"In the morning glad I see; \n",
"My foe outstretched beneath the tree.\"\"\"\n",
"\n",
"# Your code here:\n"
"poem = re.sub(r\"[^a-zA-Z]\", \" \", poem)\n",
"poem = poem.lower()\n",
"\n",
"words = poem.split()\n",
"\n",
"words = [word for word in words if word not in blacklist]\n",
"\n",
"print(words)"
]
},
{
Expand All @@ -172,14 +239,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['T', 'P']\n"
]
}
],
"source": [
"poem = \"\"\"The apparition of these faces in the crowd;\n",
"Petals on a wet, black bough.\"\"\"\n",
"\n",
"# Your code here:\n"
"uppercase_regex = r\"[A-Z]\"\n",
"uppercase_chars = re.findall(uppercase_regex, poem)\n",
"\n",
"print(uppercase_chars)\n"
]
},
{
Expand All @@ -191,13 +269,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"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"
"number_regex = r'\\d'\n",
"number_items = [item for item in data if re.search(number_regex, item)]\n",
"\n",
"print(number_items)"
]
},
{
Expand All @@ -213,18 +302,37 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"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",
"regex = r'^(?=.*\\d)(?=.*[a-z]).*$'\n",
"filtered_data = [item for item in data if re.search(regex, item)]\n",
"\n",
"print(filtered_data)"
]
},
{
"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 +346,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
}
Loading