Skip to content

Commit 951fba9

Browse files
author
Rise Riyo
committed
use list comprehension instead of for-loop to keep consistent with the previous topic
1 parent 8fcd856 commit 951fba9

File tree

1 file changed

+87
-8
lines changed

1 file changed

+87
-8
lines changed

part-4.ipynb

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:c279b3f8b75d5270e572bf063ff7315c08e1c5547ca24c870694ccddb2fb997d"
4+
"signature": "sha256:438a503ded59b13e7295fbf00a26fef4b584f4309f97d9e2a2ab45c4b291eabf"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -217,7 +217,8 @@
217217
],
218218
"language": "python",
219219
"metadata": {},
220-
"outputs": []
220+
"outputs": [],
221+
"prompt_number": 20
221222
},
222223
{
223224
"cell_type": "code",
@@ -227,7 +228,17 @@
227228
],
228229
"language": "python",
229230
"metadata": {},
230-
"outputs": []
231+
"outputs": [
232+
{
233+
"metadata": {},
234+
"output_type": "pyout",
235+
"prompt_number": 21,
236+
"text": [
237+
"'cat'"
238+
]
239+
}
240+
],
241+
"prompt_number": 21
231242
},
232243
{
233244
"cell_type": "markdown",
@@ -244,7 +255,17 @@
244255
],
245256
"language": "python",
246257
"metadata": {},
247-
"outputs": []
258+
"outputs": [
259+
{
260+
"metadata": {},
261+
"output_type": "pyout",
262+
"prompt_number": 22,
263+
"text": [
264+
"True"
265+
]
266+
}
267+
],
268+
"prompt_number": 22
248269
},
249270
{
250271
"cell_type": "markdown",
@@ -261,7 +282,17 @@
261282
],
262283
"language": "python",
263284
"metadata": {},
264-
"outputs": []
285+
"outputs": [
286+
{
287+
"metadata": {},
288+
"output_type": "pyout",
289+
"prompt_number": 23,
290+
"text": [
291+
"6"
292+
]
293+
}
294+
],
295+
"prompt_number": 23
265296
},
266297
{
267298
"cell_type": "markdown",
@@ -280,15 +311,49 @@
280311
],
281312
"language": "python",
282313
"metadata": {},
283-
"outputs": []
314+
"outputs": [
315+
{
316+
"metadata": {},
317+
"output_type": "pyout",
318+
"prompt_number": 24,
319+
"text": [
320+
"['el', 'gato', 'esta', 'en', 'la', 'casa']"
321+
]
322+
}
323+
],
324+
"prompt_number": 24
284325
},
285326
{
286327
"cell_type": "markdown",
287328
"metadata": {},
288329
"source": [
289-
"Let's loop over each word in the list and translate each one."
330+
"Let's loop over each word in the list and translate each one by using a list comprehension."
290331
]
291332
},
333+
{
334+
"cell_type": "code",
335+
"collapsed": false,
336+
"input": [
337+
"translated_words = [print(words[spanish_word]) for spanish_word in sentence_words]"
338+
],
339+
"language": "python",
340+
"metadata": {},
341+
"outputs": [
342+
{
343+
"output_type": "stream",
344+
"stream": "stdout",
345+
"text": [
346+
"the\n",
347+
"cat\n",
348+
"is\n",
349+
"in\n",
350+
"the\n",
351+
"house\n"
352+
]
353+
}
354+
],
355+
"prompt_number": 28
356+
},
292357
{
293358
"cell_type": "code",
294359
"collapsed": false,
@@ -298,7 +363,21 @@
298363
],
299364
"language": "python",
300365
"metadata": {},
301-
"outputs": []
366+
"outputs": [
367+
{
368+
"output_type": "stream",
369+
"stream": "stdout",
370+
"text": [
371+
"the\n",
372+
"cat\n",
373+
"is\n",
374+
"in\n",
375+
"the\n",
376+
"house\n"
377+
]
378+
}
379+
],
380+
"prompt_number": 25
302381
},
303382
{
304383
"cell_type": "markdown",

0 commit comments

Comments
 (0)