Skip to main content

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 for loops (so our files should still start with #level intermediate).

Class Exercises (50 mins)​

  1. Design a function my_doubles that takes a list of numbers and returns a new list where each element is twice what the corresponding element was in the original list.
  2. Re-implement the same function as my_doubles_map using the built-in map. Which implementation do you find clearer?
  3. 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.
  4. Re-implement the same function as my_string_lens_map using the built-in map. Which implementation do you find clearer?
  5. 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.
  6. Re-implement the same function as my_pos_nums_filter using the built-in filter. Which implementation do you find clearer?
  7. 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.
  8. Can you express my_alternating using either map or filter?
  9. 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].
  10. Can you express my_running_sum using either map or filter?

Wrap-up (5 mins)​

  • for loops are very expressive, but sometimes harder to understand than using built-in operations like filter or map.