Why must you loop over `range(len(L))` to change a list in place, and why does such a function return None?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
You're given the list nums = [4, 7, 1, 9]. Loop over its indices and overwrite each element with three times its value, mutating nums in place rather than building a new list. tripled is already bound to nums, so it will show the result.
Three ways to get the index inside a loop
Record that a loop over elements hands you the value without its position, then write the three alternatives: a counter incremented in the loop, range(len(L)), and for i, e in enumerate(L).
Squaring every element through L[i]
Write the body for i in range(len(L)): L[i] = L[i] ** 2 and trace [2, 3, 4] through i = 0, i = 1 and i = 2 to [4, 9, 16].
Calling a mutating function on its own line
Show L_in = [2, 3, 4] printed before and after the call with nothing saved from it, and state that assigning the call to a variable stores None.
Space cost of copying an immutable structure
Record the student or employee database example, where a tuple version rebuilds the whole structure on every change and a list updates one element in place.