September 26: Containers
Learning Objectives
After today's class, you should be able to:
- Specify which containers are mutable and immutable
- Write python code to implement and access lists, tuples, sets and dictionaries
- Use
in
andnot in
in boolean expressions - Understand the difference between
==
andis
Lesson Outline¶
Class Activity: 20 min
Mini Lecture: 25 min
Class Activity 2: 30 min
Activity to practice
Little Free Library¶
A Little Free Library is a community library that lets people borrow and contribute books. The library survives on the "take a book, leave a book" principle. If someone takes a book (like "Project Hail Mary"), they have to add another book to the library (like "The Martian"). It’s a great way for people to share books!
In this lab, you will create a library.py
program to simulate a Little Free Library.
At the top of your program, after the docstring, assign a variable named books
that contains the list of books in the library:
books = ["Project Hail Mary", "The Hobbit", "Sherlock Holmes", "The Hobbit", "Dune"]
= Little Free Library =
Count: 5 book(s)
['Project Hail Mary', 'The Hobbit', 'Sherlock Holmes', 'The Hobbit', 'Dune']
Enter the title of a book to find: The Hobbit
We have 2 copies of "The Hobbit" available.
Enter the index of a book to take: 1
You took "The Hobbit".
['Project Hail Mary', 'Sherlock Holmes', 'The Hobbit', 'Dune']
What book would you like to leave? The Martian
['Project Hail Mary', 'Sherlock Holmes', 'The Hobbit', 'Dune', 'The Martian']
Your To-Do List¶
Due Wednesday September 27th at 11pm
Prepare for Quiz 2B
- Thursday, beginning of class, 25 minutes, in EnGeo 2204.
- Two parts: concepts and programming (will use lab machine account, canvas and gradescope)
- Study chapters 3 and 4: both reading and activities
- Review class activities
- Review homework programming assignments