From d17d72285311bec9f1d3ec4d311acea8f40d20b2 Mon Sep 17 00:00:00 2001 From: Trey Hunner Date: Mon, 15 Sep 2014 13:58:31 -0700 Subject: [PATCH 1/3] Improve wording in list comprehensions example --- part-4.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/part-4.ipynb b/part-4.ipynb index 385d7f9..6283f70 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", From 5d1d6b390fe4d2d86f91f71b2f95fb3e8fdbe8ab Mon Sep 17 00:00:00 2001 From: Trey Hunner Date: Mon, 15 Sep 2014 14:21:58 -0700 Subject: [PATCH 2/3] Use a for loop in dictionary example --- part-4.ipynb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/part-4.ipynb b/part-4.ipynb index 6283f70..7680519 100644 --- a/part-4.ipynb +++ b/part-4.ipynb @@ -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": {}, From 319d914257a575e357a8c840a2507a0c745c64a9 Mon Sep 17 00:00:00 2001 From: Trey Hunner Date: Mon, 15 Sep 2014 14:23:32 -0700 Subject: [PATCH 3/3] Make more concrete exercise suggestions for part 4 --- part-4.ipynb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/part-4.ipynb b/part-4.ipynb index 7680519..92ac2b2 100644 --- a/part-4.ipynb +++ b/part-4.ipynb @@ -417,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." ]