Session 13 Preparation — Videos, Reading and Quizzes

Quizzes:

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:

In either case, bring paper copy of the completed quiz to your Session 13 class.

Videos and Reading (online and textbook):

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).

  1. Lists Operations
    • Textbook reading: Skim Section 6.2 - List Operations (pages 284 - 290, 7 pages).

      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 .

  2. Common List Algorithms
    • Textbook reading: Section 6.3 - Common List Algorithms (pages 290 - 297, 8 pages).

      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:

      • Section 6.3.7: Removing matches
      • Section 6.3.8: Swapping elements
      • Section 6.3.9: Reading input

  3. Using Lists with Functions
    • Optional textbook reading: Section 6.4 - Using Lists with Functions (pages 297 - 303, 7 pages).

      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.

  4. Problem Solving: Adapting Algorithms
    • Textbook reading: Section 6.5 - Problem Solving: Adapting Algorithms (pages 303 - 309, 7 pages).

      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.