Skip to content

Latest commit

 

History

History
65 lines (51 loc) · 1.48 KB

lec10.md

File metadata and controls

65 lines (51 loc) · 1.48 KB

Introduction to Python

Learning Objectives

  • describe which containers are mutable and which are immutable
  • use methods from each container type to efficiently manipulate a list
  • identify a specific use case for each container type

Textbook

Chapter 3, pages 65-75

Activities

  1. mutability

  2. duck typing

  3. containers - iterable

  4. lists

    • notation
    • indexing & slicing like strings
      • slicing on LHS of assignment
      • del slice
    • list operators:
      • NOT mathematical arrays
    • list methods:
      • append, count, insert, remove, clear, extend, reverse, index, pop, sort
    • testing
      • devise a way to test each function
    • reference counting
    • use cases
      • order matters
      • mutable
  5. tuples - immutable lists

    • notation
    • immutable structure
      • may have mutable members
    • what methods exist?
    • test how lists are different from tuples
    • use cases
      • order matters
      • immutable
  6. sets - unordered lists with max one of each thing

    • notation
    • items in set must be immutable
    • test addition of things to sets vs lists
    • test methods:
      • difference vs difference_update vs symmetric_difference
    • use cases
      • collect unique list of things
  7. dictionaries - powerful container type

    • notation
    • keys must be immutable
    • values can be anything - including other containers
    • explore methods
      • use what you've learned to hypothesis how they work and test those hypotheses