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
231 changes: 204 additions & 27 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": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -33,12 +33,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'Durante un tiempo no estuvo segura de si su marido era su marido'"
]
},
"execution_count": 4,
"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,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Bananas , Chocolate , bread , diapers , Ice Cream , Brownie Mix , broccoli\n",
"['bananas', 'bread', 'brownie', 'broccoli']\n"
]
}
],
"source": [
"food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n",
"# Your code here:\n"
"# Your code here:\n",
"grocery_list= \" , \".join(food_list)\n",
"print(grocery_list)\n",
"grocery_list=grocery_list.lower()\n",
"rule='[b][a-z]+'\n",
"grocery_list=re.findall(rule,grocery_list)\n",
"print(grocery_list)"
]
},
{
Expand All @@ -69,9 +96,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 35,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'The area of the circle with radius: 4.5 is: 63.61725123519331'"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import math\n",
"\n",
Expand All @@ -90,7 +128,9 @@
" # Your code here:\n",
" return pi * (x**2)\n",
" \n",
"# Your output string here:\n"
"# Your output string here:\n",
"area=str(area(radius,pi=math.pi))\n",
"f\"{string1} {str(radius)} {string2} {str(area)}\""
]
},
{
Expand All @@ -106,9 +146,64 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 41,
"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",
"Frequency of Some is : 1\n",
"Frequency of say is : 3\n",
"Frequency of the is : 1\n",
"Frequency of world is : 1\n",
"Frequency of will is : 1\n",
"Frequency of end is : 1\n",
"Frequency of in is : 2\n",
"Frequency of fire,\n",
"Some is : 1\n",
"Frequency of ice.\n",
"From is : 1\n",
"Frequency of what is : 1\n",
"Frequency of I’ve is : 1\n",
"Frequency of tasted is : 1\n",
"Frequency of of is : 2\n",
"Frequency of desire\n",
"I is : 1\n",
"Frequency of hold is : 1\n",
"Frequency of with is : 1\n",
"Frequency of those is : 1\n",
"Frequency of who is : 1\n",
"Frequency of favor is : 1\n",
"Frequency of fire.\n",
"But is : 1\n",
"Frequency of if is : 1\n",
"Frequency of it is : 1\n",
"Frequency of had is : 1\n",
"Frequency of to is : 1\n",
"Frequency of perish is : 1\n",
"Frequency of twice,\n",
"I is : 1\n",
"Frequency of think is : 1\n",
"Frequency of I is : 1\n",
"Frequency of know is : 1\n",
"Frequency of enough is : 1\n",
"Frequency of hate\n",
"To is : 1\n",
"Frequency of that is : 1\n",
"Frequency of for is : 1\n",
"Frequency of destruction is : 1\n",
"Frequency of ice\n",
"Is is : 1\n",
"Frequency of also is : 1\n",
"Frequency of great\n",
"And is : 1\n",
"Frequency of would is : 1\n",
"Frequency of suffice. is : 1\n"
]
}
],
"source": [
"poem = \"\"\"Some say the world will end in fire,\n",
"Some say in ice.\n",
Expand All @@ -120,7 +215,19 @@
"Is also great\n",
"And would suffice.\"\"\"\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"word_split=poem.split(\" \")\n",
"print(word_split) \n",
"word_list = []\n",
" \n",
" # loop till string values present in list str\n",
"for i in word_split: \n",
" if i not in word_list:\n",
" word_list.append(i) \n",
" \n",
"for i in range(0, len(word_list)):\n",
"\n",
" print('Frequency of', word_list[i], 'is :', word_split.count(word_list[i])) \n"
]
},
{
Expand All @@ -132,9 +239,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Words in poem : \n",
" ['i', 'was', 'angry', 'with', 'my', 'friend', 'i', 'told', 'my', 'wrath', 'my', 'wrath', 'did', 'end', 'i', 'was', 'angry', 'with', 'my', 'foe', 'i', 'told', 'it', 'not', 'my', 'wrath', 'did', 'grow', 'and', 'i', 'waterd', 'it', 'in', 'fears', 'night', 'morning', 'with', 'my', 'tears', 'and', 'i', 'sunned', 'it', 'with', 'smiles', 'and', 'with', 'soft', 'deceitful', 'wiles', 'and', 'it', 'grew', 'both', 'day', 'and', 'night', 'till', 'it', 'bore', 'an', 'apple', 'bright', 'and', 'my', 'foe', 'beheld', 'it', 'shine', 'and', 'he', 'knew', 'that', 'it', 'was', 'mine', 'and', 'into', 'my', 'garden', 'stole', 'when', 'the', 'night', 'had', 'veild', 'the', 'pole', 'in', 'the', 'morning', 'glad', 'i', 'see', 'my', 'foe', 'outstretched', 'beneath', 'the', 'tree', '']\n",
"Words in poem that are not in blacklist: \n",
" ['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 +276,18 @@
"In the morning glad I see; \n",
"My foe outstretched beneath the tree.\"\"\"\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"\n",
"poem_clean=re.sub('[^A-Za-z0-9]+',' ', poem)\n",
"poem_clean=poem_clean.lower()\n",
"poem_words=poem_clean.split(\" \")\n",
"print(\"Words in poem :\",\"\\n\",poem_words)\n",
"\n",
"non_blacklist=[]\n",
"for i in poem_words:\n",
" if i not in blacklist:\n",
" non_blacklist.append(i)\n",
"print(\"Words in poem that are not in blacklist:\",\"\\n\", non_blacklist)"
]
},
{
Expand All @@ -172,16 +301,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"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"
"# Your code here:\n",
"uppercase=[]\n",
"for l in poem:\n",
" if l.isupper()==True:\n",
" uppercase.append(l)\n",
"print(uppercase)"
]
},
{
Expand All @@ -193,13 +335,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 43,
"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"
"# Your code here:\n",
"number_element=[]\n",
"for i in data:\n",
" if re.search(\"[0-9]+\",i)!=None:\n",
" number_element.append(i)\n",
"\n",
"print(number_element)"
]
},
{
Expand All @@ -215,18 +371,39 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 42,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['123abc', 'abc123', 'JohnSmith1', 'ABBY4']\n"
]
}
],
"source": [
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
"# Your code here:\n"
"# Your code here:\n",
"number_element=[]\n",
"for i in data:\n",
" if re.search(\"[a-z0-9]\",i)!=None:\n",
" number_element.append(i)\n",
"\n",
"print(number_element)"
]
},
{
"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 +417,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
Loading