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.
Turn it in via the Session 13 Dropbox on our Moodle site.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).
This link discusses list mutations, as well as the differences between lists and tuples. Be sure to click the buttons at the end, there is more than is originally shown, but you must click the buttons to reveal it.
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.