Skip to content

Commit 77335b7

Browse files
committed
Merge pull request #32 from pythonsd/part-4-suggestions
Merges suggested improvements for part 4
2 parents 48e9c89 + 319d914 commit 77335b7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

part-4.ipynb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@
110110
"cell_type": "markdown",
111111
"metadata": {},
112112
"source": [
113-
"Note how our list comprehension is written within the brackets: The for-loop statement is written at the end whereas the action inside of the for-loop is written first: n * n"
113+
"Note how our list comprehension is written within the brackets: The list we're looping over (my_favorite_numbers) is written at the end whereas the action inside of the for-loop is written first: n * n"
114114
]
115115
},
116116
{
117117
"cell_type": "markdown",
118118
"metadata": {},
119119
"source": [
120-
"Let's revisit a problem we've already solved in Danny's lecture on list:\n",
120+
"Let's revisit a problem we've already solved in Danny's lecture on lists:\n",
121121
"\n",
122122
"Pick every name from a list that begins with a vowel.\n",
123123
"\n",
@@ -321,14 +321,16 @@
321321
"cell_type": "markdown",
322322
"metadata": {},
323323
"source": [
324-
"Let's translate each word and save them in the list called translated_words. We'll generate this list by using a list comprehension."
324+
"Let's translate each word and save them in the list called translated_words. Let's start with an empty list and use a for loop to populate our list:"
325325
]
326326
},
327327
{
328328
"cell_type": "code",
329329
"collapsed": false,
330330
"input": [
331-
"translated_words = [print(words[spanish_word]) for spanish_word in sentence_words]"
331+
"translated_words = []\n",
332+
"for spanish_word in sentence_words:\n",
333+
" translated_words.append(words[spanish_word])"
332334
],
333335
"language": "python",
334336
"metadata": {},
@@ -505,7 +507,13 @@
505507
"cell_type": "markdown",
506508
"metadata": {},
507509
"source": [
508-
"**Extra Credit:** Try using a list comprehension in the translate function.\n",
510+
"**Exercises:**\n",
511+
"\n",
512+
"1. Make a new py file and put that translate function in the file. Use the print function to print out some examples of using the function.\n",
513+
"\n",
514+
"2. Refactor the translate function to use a list comprehension.\n",
515+
"\n",
516+
"3. There are lots of ways to write that translate function. Just for fun, see if you can write the whole translate function in one line.\n",
509517
"\n",
510518
"**Note:** Typing out the exercises for the next section, \"Sets\", is optional. If your brain is melting, feel free to sit back, relax, and enjoy the rest of the lecture."
511519
]

0 commit comments

Comments
 (0)