Skip to content

Commit c7bdc90

Browse files
author
Rise Riyo
committed
use list comprehension in translate function instead of a for-loop
1 parent ffcbd82 commit c7bdc90

File tree

1 file changed

+18
-43
lines changed

1 file changed

+18
-43
lines changed

part-4.ipynb

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:6d49e8f391efd616a50a4c712a7081065abec4b33a013ba183f59e755696f1f5"
4+
"signature": "sha256:1ea7dc49f946546b6ab2dc4d73a06849f0f6994a0ee6912c4368f0caf20e1f3f"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -297,21 +297,7 @@
297297
],
298298
"language": "python",
299299
"metadata": {},
300-
"outputs": [
301-
{
302-
"output_type": "stream",
303-
"stream": "stdout",
304-
"text": [
305-
"the\n",
306-
"cat\n",
307-
"is\n",
308-
"in\n",
309-
"the\n",
310-
"house\n"
311-
]
312-
}
313-
],
314-
"prompt_number": 29
300+
"outputs": []
315301
},
316302
{
317303
"cell_type": "code",
@@ -321,17 +307,7 @@
321307
],
322308
"language": "python",
323309
"metadata": {},
324-
"outputs": [
325-
{
326-
"metadata": {},
327-
"output_type": "pyout",
328-
"prompt_number": 31,
329-
"text": [
330-
"['the', 'cat', 'is', 'in', 'the', 'house']"
331-
]
332-
}
333-
],
334-
"prompt_number": 31
310+
"outputs": []
335311
},
336312
{
337313
"cell_type": "markdown",
@@ -349,17 +325,7 @@
349325
],
350326
"language": "python",
351327
"metadata": {},
352-
"outputs": [
353-
{
354-
"metadata": {},
355-
"output_type": "pyout",
356-
"prompt_number": 32,
357-
"text": [
358-
"'the cat is in the house'"
359-
]
360-
}
361-
],
362-
"prompt_number": 32
328+
"outputs": []
363329
},
364330
{
365331
"cell_type": "markdown",
@@ -387,14 +353,13 @@
387353
"\n",
388354
"def translate(sentence):\n",
389355
" spanish_words = sentence.split()\n",
390-
" english_words = []\n",
391-
" for w in spanish_words:\n",
392-
" english_words.append(words[w])\n",
356+
" english_words = [words[w] for w in spanish_words]\n",
393357
" return \" \".join(english_words)"
394358
],
395359
"language": "python",
396360
"metadata": {},
397-
"outputs": []
361+
"outputs": [],
362+
"prompt_number": 35
398363
},
399364
{
400365
"cell_type": "code",
@@ -404,7 +369,17 @@
404369
],
405370
"language": "python",
406371
"metadata": {},
407-
"outputs": []
372+
"outputs": [
373+
{
374+
"metadata": {},
375+
"output_type": "pyout",
376+
"prompt_number": 36,
377+
"text": [
378+
"'the dog ate the burrito green'"
379+
]
380+
}
381+
],
382+
"prompt_number": 36
408383
},
409384
{
410385
"cell_type": "code",

0 commit comments

Comments
 (0)