COMPSCI 61A Lecture 12: Mutable Sequences
zogo39484755 and 6 others unlocked
22
COMPSCI 61A Full Course Notes
Verified Note
22 documents
Document Summary
To explore the power of values that can mutate, or change. Data abstraction allows us to think of compound/complex values as objects. Many compound values have state that changes over time (property of being mutable) Returns last element and removes it from list list. extend([sub-list]) Adds sub-list to the end of a list. Can"t be mutable values, such as lists and dictionaries. You can use a tuple as a dictionary key, but you can"t use a list (or a tuple that contains a list) as a dictionary key. Not only does your dictionary key have to be immutable, it must contain all immutable values. If you want to associate multiple values with a key, store them all in a sequence value. A function can change the value of any object in its scope. Even though an object is bound to something in the global frame, if it is referenced within a function it can be mutated in the global frame.