Skip to content

Commit 52ae9f6

Browse files
committed
strings done
1 parent fd274c4 commit 52ae9f6

File tree

2 files changed

+249
-50
lines changed

2 files changed

+249
-50
lines changed

your-code/challenge-1.ipynb

Lines changed: 146 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
{
1717
"cell_type": "code",
18-
"execution_count": null,
18+
"execution_count": 2,
1919
"metadata": {},
2020
"outputs": [],
2121
"source": [
@@ -33,12 +33,24 @@
3333
},
3434
{
3535
"cell_type": "code",
36-
"execution_count": null,
36+
"execution_count": 3,
3737
"metadata": {},
38-
"outputs": [],
38+
"outputs": [
39+
{
40+
"data": {
41+
"text/plain": [
42+
"'Durante un tiempo no estuvo segura de si su marido era su marido.'"
43+
]
44+
},
45+
"execution_count": 3,
46+
"metadata": {},
47+
"output_type": "execute_result"
48+
}
49+
],
3950
"source": [
4051
"str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n",
41-
"# Your code here:\n"
52+
"# Your code here:\n",
53+
"\" \".join(str_list)+\".\""
4254
]
4355
},
4456
{
@@ -50,12 +62,28 @@
5062
},
5163
{
5264
"cell_type": "code",
53-
"execution_count": null,
65+
"execution_count": 4,
5466
"metadata": {},
55-
"outputs": [],
67+
"outputs": [
68+
{
69+
"name": "stdout",
70+
"output_type": "stream",
71+
"text": [
72+
"Grocery list: bananas, bread, brownie mix, broccoli.\n"
73+
]
74+
}
75+
],
5676
"source": [
5777
"food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n",
58-
"# Your code here:\n"
78+
"# Your code here:\n",
79+
"#\"Grocery list: \"+\", \".join(food_list).lower()+\".\" #if i want to present all the list in the Grocery list\n",
80+
"#to include only the food that starts with b\n",
81+
"bfood_list=[]\n",
82+
"for i in food_list:\n",
83+
" if i[0].lower()==\"b\":\n",
84+
" bfood_list.append(i)\n",
85+
"#print(bfood_list)\n",
86+
"print(\"Grocery list: \"+\", \".join(bfood_list).lower()+\".\")\n"
5987
]
6088
},
6189
{
@@ -69,9 +97,27 @@
6997
},
7098
{
7199
"cell_type": "code",
72-
"execution_count": null,
100+
"execution_count": 5,
73101
"metadata": {},
74-
"outputs": [],
102+
"outputs": [
103+
{
104+
"name": "stdout",
105+
"output_type": "stream",
106+
"text": [
107+
"The area of the circle with radius: 4.5 is: 63.61725123519331\n"
108+
]
109+
},
110+
{
111+
"data": {
112+
"text/plain": [
113+
"'The area of the circle with radius: 4.5 is: 63.61725123519331 '"
114+
]
115+
},
116+
"execution_count": 5,
117+
"metadata": {},
118+
"output_type": "execute_result"
119+
}
120+
],
75121
"source": [
76122
"import math\n",
77123
"\n",
@@ -90,7 +136,9 @@
90136
" # Your code here:\n",
91137
" return pi * (x**2)\n",
92138
" \n",
93-
"# Your output string here:\n"
139+
"# Your output string here:\n",
140+
"print(string1,radius,string2,area(radius))\n",
141+
"f\"The area of the circle with radius: {radius} is: {area(radius)} \""
94142
]
95143
},
96144
{
@@ -106,9 +154,17 @@
106154
},
107155
{
108156
"cell_type": "code",
109-
"execution_count": null,
157+
"execution_count": 11,
110158
"metadata": {},
111-
"outputs": [],
159+
"outputs": [
160+
{
161+
"name": "stdout",
162+
"output_type": "stream",
163+
"text": [
164+
"{'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"
165+
]
166+
}
167+
],
112168
"source": [
113169
"poem = \"\"\"Some say the world will end in fire,\n",
114170
"Some say in ice.\n",
@@ -120,7 +176,14 @@
120176
"Is also great\n",
121177
"And would suffice.\"\"\"\n",
122178
"\n",
123-
"# Your code here:\n"
179+
"# Your code here:\n",
180+
"list1=re.split(\" \",poem.replace(\"\\n\",\" \").replace(\",\",\"\").replace(\".\",\"\"))\n",
181+
"#print(list1)\n",
182+
"dict1={}\n",
183+
"for i in list1:\n",
184+
" dict1[i]=list1.count(i)\n",
185+
"print(dict1)\n",
186+
"\n"
124187
]
125188
},
126189
{
@@ -132,9 +195,17 @@
132195
},
133196
{
134197
"cell_type": "code",
135-
"execution_count": null,
198+
"execution_count": 7,
136199
"metadata": {},
137-
"outputs": [],
200+
"outputs": [
201+
{
202+
"name": "stdout",
203+
"output_type": "stream",
204+
"text": [
205+
"['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', 'i', 'waterd', 'it', 'in', 'fears', 'night', 'morning', 'with', 'my', 'tears', 'i', 'sunned', 'it', 'with', 'smiles', 'with', 'soft', 'deceitful', 'wiles', 'it', 'grew', 'both', 'day', 'night', 'till', 'it', 'bore', 'an', 'apple', 'bright', 'my', 'foe', 'beheld', 'it', 'shine', 'he', 'knew', 'that', 'it', 'was', 'mine', 'into', 'my', 'garden', 'stole', 'when', 'the', 'night', 'had', 'veild', 'the', 'pole', 'in', 'the', 'morning', 'glad', 'i', 'see', 'my', 'foe', 'outstretched', 'beneath', 'the', 'tree']\n"
206+
]
207+
}
208+
],
138209
"source": [
139210
"blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n",
140211
"\n",
@@ -158,7 +229,21 @@
158229
"In the morning glad I see; \n",
159230
"My foe outstretched beneath the tree.\"\"\"\n",
160231
"\n",
161-
"# Your code here:\n"
232+
"# Your code here:\n",
233+
"wordslist=re.findall('\\w+',poem)\n",
234+
"#print(wordslist)\n",
235+
"list2=[]\n",
236+
"for j in blacklist:\n",
237+
" for i in wordslist:\n",
238+
" if i.lower()==j:\n",
239+
" continue\n",
240+
" else:\n",
241+
" list2.append(i.lower())\n",
242+
" break\n",
243+
"print(list2)\n",
244+
"\n",
245+
"\n",
246+
"\n"
162247
]
163248
},
164249
{
@@ -172,16 +257,25 @@
172257
},
173258
{
174259
"cell_type": "code",
175-
"execution_count": null,
260+
"execution_count": 8,
176261
"metadata": {},
177-
"outputs": [],
262+
"outputs": [
263+
{
264+
"name": "stdout",
265+
"output_type": "stream",
266+
"text": [
267+
"['T', 'P']\n"
268+
]
269+
}
270+
],
178271
"source": [
179272
"import re\n",
180273
"\n",
181274
"poem = \"\"\"The apparition of these faces in the crowd;\n",
182275
"Petals on a wet, black bough.\"\"\"\n",
183276
"\n",
184-
"# Your code here:\n"
277+
"# Your code here:\n",
278+
"print(re.findall('[A-Z]', poem))"
185279
]
186280
},
187281
{
@@ -193,13 +287,23 @@
193287
},
194288
{
195289
"cell_type": "code",
196-
"execution_count": null,
290+
"execution_count": 9,
197291
"metadata": {},
198-
"outputs": [],
292+
"outputs": [
293+
{
294+
"name": "stdout",
295+
"output_type": "stream",
296+
"text": [
297+
"['123abc', 'abc123', 'JohnSmith1', 'ABBY4']\n"
298+
]
299+
}
300+
],
199301
"source": [
200302
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
201303
"\n",
202-
"# Your code here:\n"
304+
"# Your code here:\n",
305+
"data_filtered=[element for element in data if re.search(\"[0-9]\",element)]\n",
306+
"print(data_filtered)"
203307
]
204308
},
205309
{
@@ -215,18 +319,28 @@
215319
},
216320
{
217321
"cell_type": "code",
218-
"execution_count": null,
322+
"execution_count": 10,
219323
"metadata": {},
220-
"outputs": [],
324+
"outputs": [
325+
{
326+
"name": "stdout",
327+
"output_type": "stream",
328+
"text": [
329+
"['123abc', 'abc123', 'JohnSmith1']\n"
330+
]
331+
}
332+
],
221333
"source": [
222334
"data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
223-
"# Your code here:\n"
335+
"# Your code here:\n",
336+
"data_filtered2=[element for element in data if re.search(\"(?=.*\\d)(?=.*[a-z])\",element)]\n",
337+
"print(data_filtered2)"
224338
]
225339
}
226340
],
227341
"metadata": {
228342
"kernelspec": {
229-
"display_name": "Python 3",
343+
"display_name": "Python 3.9.12 ('base')",
230344
"language": "python",
231345
"name": "python3"
232346
},
@@ -240,7 +354,12 @@
240354
"name": "python",
241355
"nbconvert_exporter": "python",
242356
"pygments_lexer": "ipython3",
243-
"version": "3.6.8"
357+
"version": "3.9.12"
358+
},
359+
"vscode": {
360+
"interpreter": {
361+
"hash": "d3d1cb76b10a4ded1b8898b657b0b01234f45abbde55e4ed76ad39e6a18c979c"
362+
}
244363
}
245364
},
246365
"nbformat": 4,

0 commit comments

Comments
 (0)