|
15 | 15 | },
|
16 | 16 | {
|
17 | 17 | "cell_type": "code",
|
18 |
| - "execution_count": null, |
| 18 | + "execution_count": 2, |
19 | 19 | "metadata": {},
|
20 | 20 | "outputs": [],
|
21 | 21 | "source": [
|
|
33 | 33 | },
|
34 | 34 | {
|
35 | 35 | "cell_type": "code",
|
36 |
| - "execution_count": null, |
| 36 | + "execution_count": 3, |
37 | 37 | "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 | + ], |
39 | 50 | "source": [
|
40 | 51 | "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)+\".\"" |
42 | 54 | ]
|
43 | 55 | },
|
44 | 56 | {
|
|
50 | 62 | },
|
51 | 63 | {
|
52 | 64 | "cell_type": "code",
|
53 |
| - "execution_count": null, |
| 65 | + "execution_count": 4, |
54 | 66 | "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 | + ], |
56 | 76 | "source": [
|
57 | 77 | "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" |
59 | 87 | ]
|
60 | 88 | },
|
61 | 89 | {
|
|
69 | 97 | },
|
70 | 98 | {
|
71 | 99 | "cell_type": "code",
|
72 |
| - "execution_count": null, |
| 100 | + "execution_count": 5, |
73 | 101 | "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 | + ], |
75 | 121 | "source": [
|
76 | 122 | "import math\n",
|
77 | 123 | "\n",
|
|
90 | 136 | " # Your code here:\n",
|
91 | 137 | " return pi * (x**2)\n",
|
92 | 138 | " \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)} \"" |
94 | 142 | ]
|
95 | 143 | },
|
96 | 144 | {
|
|
106 | 154 | },
|
107 | 155 | {
|
108 | 156 | "cell_type": "code",
|
109 |
| - "execution_count": null, |
| 157 | + "execution_count": 11, |
110 | 158 | "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 | + ], |
112 | 168 | "source": [
|
113 | 169 | "poem = \"\"\"Some say the world will end in fire,\n",
|
114 | 170 | "Some say in ice.\n",
|
|
120 | 176 | "Is also great\n",
|
121 | 177 | "And would suffice.\"\"\"\n",
|
122 | 178 | "\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" |
124 | 187 | ]
|
125 | 188 | },
|
126 | 189 | {
|
|
132 | 195 | },
|
133 | 196 | {
|
134 | 197 | "cell_type": "code",
|
135 |
| - "execution_count": null, |
| 198 | + "execution_count": 7, |
136 | 199 | "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 | + ], |
138 | 209 | "source": [
|
139 | 210 | "blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n",
|
140 | 211 | "\n",
|
|
158 | 229 | "In the morning glad I see; \n",
|
159 | 230 | "My foe outstretched beneath the tree.\"\"\"\n",
|
160 | 231 | "\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" |
162 | 247 | ]
|
163 | 248 | },
|
164 | 249 | {
|
|
172 | 257 | },
|
173 | 258 | {
|
174 | 259 | "cell_type": "code",
|
175 |
| - "execution_count": null, |
| 260 | + "execution_count": 8, |
176 | 261 | "metadata": {},
|
177 |
| - "outputs": [], |
| 262 | + "outputs": [ |
| 263 | + { |
| 264 | + "name": "stdout", |
| 265 | + "output_type": "stream", |
| 266 | + "text": [ |
| 267 | + "['T', 'P']\n" |
| 268 | + ] |
| 269 | + } |
| 270 | + ], |
178 | 271 | "source": [
|
179 | 272 | "import re\n",
|
180 | 273 | "\n",
|
181 | 274 | "poem = \"\"\"The apparition of these faces in the crowd;\n",
|
182 | 275 | "Petals on a wet, black bough.\"\"\"\n",
|
183 | 276 | "\n",
|
184 |
| - "# Your code here:\n" |
| 277 | + "# Your code here:\n", |
| 278 | + "print(re.findall('[A-Z]', poem))" |
185 | 279 | ]
|
186 | 280 | },
|
187 | 281 | {
|
|
193 | 287 | },
|
194 | 288 | {
|
195 | 289 | "cell_type": "code",
|
196 |
| - "execution_count": null, |
| 290 | + "execution_count": 9, |
197 | 291 | "metadata": {},
|
198 |
| - "outputs": [], |
| 292 | + "outputs": [ |
| 293 | + { |
| 294 | + "name": "stdout", |
| 295 | + "output_type": "stream", |
| 296 | + "text": [ |
| 297 | + "['123abc', 'abc123', 'JohnSmith1', 'ABBY4']\n" |
| 298 | + ] |
| 299 | + } |
| 300 | + ], |
199 | 301 | "source": [
|
200 | 302 | "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n",
|
201 | 303 | "\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)" |
203 | 307 | ]
|
204 | 308 | },
|
205 | 309 | {
|
|
215 | 319 | },
|
216 | 320 | {
|
217 | 321 | "cell_type": "code",
|
218 |
| - "execution_count": null, |
| 322 | + "execution_count": 10, |
219 | 323 | "metadata": {},
|
220 |
| - "outputs": [], |
| 324 | + "outputs": [ |
| 325 | + { |
| 326 | + "name": "stdout", |
| 327 | + "output_type": "stream", |
| 328 | + "text": [ |
| 329 | + "['123abc', 'abc123', 'JohnSmith1']\n" |
| 330 | + ] |
| 331 | + } |
| 332 | + ], |
221 | 333 | "source": [
|
222 | 334 | "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)" |
224 | 338 | ]
|
225 | 339 | }
|
226 | 340 | ],
|
227 | 341 | "metadata": {
|
228 | 342 | "kernelspec": {
|
229 |
| - "display_name": "Python 3", |
| 343 | + "display_name": "Python 3.9.12 ('base')", |
230 | 344 | "language": "python",
|
231 | 345 | "name": "python3"
|
232 | 346 | },
|
|
240 | 354 | "name": "python",
|
241 | 355 | "nbconvert_exporter": "python",
|
242 | 356 | "pygments_lexer": "ipython3",
|
243 |
| - "version": "3.6.8" |
| 357 | + "version": "3.9.12" |
| 358 | + }, |
| 359 | + "vscode": { |
| 360 | + "interpreter": { |
| 361 | + "hash": "d3d1cb76b10a4ded1b8898b657b0b01234f45abbde55e4ed76ad39e6a18c979c" |
| 362 | + } |
244 | 363 | }
|
245 | 364 | },
|
246 | 365 | "nbformat": 4,
|
|
0 commit comments