Class 16 - Working with Lists
Date: October 19, 2026
⚠️Homework
Homework 6 due October 25, 2026
‼️Ending Skills
Last week for skills: 3
🆕New Skills
First week for skills: 4
Skills: 4
Recap (5 mins)
- Today we will continue practicing with
forloops (so our files should still start with#level intermediate).
Class Exercises (50 mins)
- Design a function
my_doublesthat takes a list of numbers and returns a new list where each element is twice what the corresponding element was in the original list. - Re-implement the same function as
my_doubles_mapusing the built-inmap. Which implementation do you find clearer? - Design
my_string_lens, which takes a list of strings and returns a new list where each element is the length of the string in the corresponding position in the input list. - Re-implement the same function as
my_string_lens_mapusing the built-inmap. Which implementation do you find clearer? - Design
my_pos_nums, which takes a list of numbers and returns a new list that contains only those numbers in the original list that are positive. - Re-implement the same function as
my_pos_nums_filterusing the built-infilter. Which implementation do you find clearer? - Design
my_alternating, which takes a list of any element and returns a new list that contains every other element -- i.e., keep the first, skip the second, etc. Note: you may need two variables that change for this one -- one to contain the result, as normal, but the other to keep track of the alternation. - Can you express
my_alternatingusing eithermaporfilter? - Design
my_running_sum, that takes a list of numbers and returns a list where each position contains a sum of the numbers in the original list up to the corresponding position. i.e.,my_running_sum([1, 2, 3]) == [1, 3, 6]. - Can you express
my_running_sumusing eithermaporfilter?
Wrap-up (5 mins)
forloops are very expressive, but sometimes harder to understand than using built-in operations likefilterormap.