We will review list slicing and list comprehensions as ways to manipulate
lists.
We will also take a look at tuples, which are similar to lists but immutable.
# To prepare for lecture:
### To read/watch before lecture:
- Here's a video that reviews much of what was covered in lecture earlier this
semester on list/string slicing:
Slicing
Lists and Strings
- Here's a video that reviews what we saw of list comprehensions earlier this
semester. I like that the presenter shows the equivalent for-loop version
for each example:
List Comprehensions
- Finally, minutes 20:16-23:35 of the following video does a quick overview
of tuples (you watched the first 20 minutes of this video for our March 30
lecture on lists):
Lists, Tuples, and Sets
- If you haven't already, you should also take a look at part 2 of assignment 8.
### Worksheet:
We'll be going over questions from the
worksheet exercise27.pdf.
- The first question on this worksheet reviews slicing strings and lists. We'll
talk about sequences in Python.
- The second question reviews list comprehensions. We'll talk about
map/filter operations.
- Questions 3, 4, and 5 are for practice with tuples (another sequence type).
- The remaining questions highlight why it's important to have a
good mental model in general, but specifically in the context of
lists. We won't get through all of these questions and, honestly, it's
fine if we don't get to any of them on Monday since I plan to talk a lot
more about this in Wednesday's lecture.
# Notes from after lecture:
- We went through exercises 1-5 from the worksheet, discussing
sequence types, doing lots of examples of list comprehension, and
talking about tuples. Then we went quickly through exercise 6,
which hinted at why there's more to talk about regarding using
nested structures such as lists of lists. The
marked up version of the worksheet is
here. The code
is here.
- The video is on Box and
available here.
I editted out me trying to figure out why breakout rooms weren't
working and also a few other quiet portions during which everyone was
entering things in the spreadsheet. Hopefully this makes it a little
easier to watch!