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: <a href="https://www.youtube.com/watch?v=ajrtAuDg3yw">Slicing Lists and Strings</a> - 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: <a href="https://www.youtube.com/watch?v=7G0jqG_kiig">List Comprehensions</a> - 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): <a href="https://www.youtube.com/watch?v=W8KRzm-HUcc">Lists, Tuples, and Sets</a> - 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 <a href="./exercises27.pdf">exercise27.pdf</a>. - 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 <a href="./exercises27_markup.pdf">here</a>. The code is <a href="./lec27code.py">here</a>. - The video is on Box and available <a href="https://pomona.box.com/s/22bse28tr1xmb2j45tbzsaux4r2d7whd">here</a>. 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!