Do this Quiz on Session 13 as you watch the videos and do the reading (as listed below). This document is a Microsoft Word document; here is the same Quiz on Session 13 (pdf) as a PDF.
You can either:
All of the following are required except any items labeled Optional are, well, optional (i.e., things that may be interesting but do not directly pertain to your success in this course).
Executive summary: This section presents some useful list operations (functions and methods). You could find many of them by using the “dot trick”, but it is handy to see them in writing. All of them do mutation “under the hood” when necessary to accomplish their ends efficiently.
Note especially section 6.2.6 on equality-testing and Table 1 Common List Functions and Operators .
Executive summary: You saw many of these algorithms in videos and exercises from previous sessions. However, the following sections cover algorithms that we have not discussed explicitly elsewhere:
Executive summary:
As you have seen, calling a function, e.g.
foo(x)
never re-assigns the value of x in the caller's namespace,
even if the function call re-assigns the corresponding parameter in the function's namespace.
That is, when the above function call returns to the caller,
the variable x is guaranteed to refer to the same object that it did
prior to the function call.
But as you have also seen, if the argument is a mutable object like a list, there is a “catch”: the function call can change the “insides” of the object. That is the function call can mutate the object.
For example, if the function definition is something like:
def foo(x):
foo[...] = ...
then upon the return to the caller, items inside the list x
are re-assigned, even though x itself continues to refer to the same object
to which it referred before the call.
This section repeats this explanation in detail with enlightening diagrams and examples, in the context of lists. Most of which it says also applies to any mutable object.
Executive summary: This important section introduces what we will be doing over the next several sessions: helping you see how to break a larger problem into smaller sub-problems.
Pay special attention to Worked Example 6.1: Rolling the Dice.