Why does a recursive search that only recurses on L[1:] find 1 in [2, 5, 8, 1] but miss it in [2, 1, 5, 8] — and how do print statements expose the skipped element?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Here is the tempting first version of the membership test, with one extra line at the very top of the body so that every call announces the list it is currently examining:
## incorrect def in_list(L, e): print(L) if len(L) == 1: return L[0] == e else: return in_list(L[1:], e)
Someone runs in_list([7, 3, 9, 4], 9). Assign to trace a list of lists: the value each call prints, in the order the calls happen.