diff --git a/part-4.ipynb b/part-4.ipynb index 385d7f9..92ac2b2 100644 --- a/part-4.ipynb +++ b/part-4.ipynb @@ -110,14 +110,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "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" + "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" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Let's revisit a problem we've already solved in Danny's lecture on list:\n", + "Let's revisit a problem we've already solved in Danny's lecture on lists:\n", "\n", "Pick every name from a list that begins with a vowel.\n", "\n", @@ -286,14 +286,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Let's translate each word and save them in the list called translated_words. We'll generate this list by using a list comprehension." + "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:" ] }, { "cell_type": "code", "collapsed": false, "input": [ - "translated_words = [print(words[spanish_word]) for spanish_word in sentence_words]" + "translated_words = []\n", + "for spanish_word in sentence_words:\n", + " translated_words.append(words[spanish_word])" ], "language": "python", "metadata": {}, @@ -415,7 +417,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Extra Credit:** Try using a list comprehension in the translate function.\n", + "**Exercises:**\n", + "\n", + "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", + "\n", + "2. Refactor the translate function to use a list comprehension.\n", + "\n", + "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", "\n", "**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." ]