Skip to content

Suggested improvements for part 4 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 19, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions part-4.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {},
Expand Down Expand Up @@ -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."
]
Expand Down