Quick References
Before we begin, here are quick links to our course cheatsheets. These may be helpful during the exercise:
Feel free to refer to these cheatsheets throughout the exercise if you need a quick reminder about syntax or functionality.
Introduction to Paired Programming (5 minutes)
Welcome to todayβs Coding Colab! In this session, youβll be working in pairs to explore and reinforce your understanding of lists and dictionaries, while also discovering the unique features of sets.
Benefits of Paired Programming
- Knowledge sharing: Learn from each otherβs experiences and approaches.
- Improved code quality: Catch errors earlier with two sets of eyes.
- Enhanced problem-solving: Discuss ideas for more creative solutions.
- Skill development: Improve communication and teamwork skills.
How to Make the Most of Paired Programming
- Assign roles: One person is the βdriverβ (typing), the other is the βnavigatorβ (reviewing).
- Switch roles regularly: Swap every 10-15 minutes to stay engaged.
- Communicate clearly: Explain your thought process and ask questions.
- Be open to ideas: Listen to your partnerβs suggestions.
- Stay focused: Keep the conversation relevant to the task.
Exercise Overview
This Coding Colab will reinforce your understanding of lists and dictionaries while introducing you to sets. Youβll work through a series of tasks, discussing and implementing solutions together.
Part 1: Lists and Dictionaries Review (15 minutes)
Task 1: List Operations
Create a list of your favorite fruits and perform the following operations:
- Create a list called
fruits
with at least 3 fruit names. - Add a new fruit to the end of the list.
- Remove the second fruit from the list.
- Print the final list.
Task 2: Dictionary Operations
Create a dictionary representing a simple inventory system:
- Create a dictionary called
inventory
with at least 3 items and their quantities. - Add a new item to the inventory.
- Update the quantity of an existing item.
- Print the final inventory.
Part 2: Introducing Sets (15 minutes)
Hereβs a Sets Cheatsheet. Sets are a lot like lists, so take a look at the cheatsheet to see how they are created and manipulated!
Task 3: Creating and Manipulating Sets
- Create two sets:
evens
with even numbers from 2 to 10, andodds
with odd numbers from 1 to 9. - Print both sets.
- Find and print the union of the two sets.
- Find and print the intersection of the two sets.
- Add a new element to the
evens
set.
Task 4: Combining Set Operations and List Operations
Using a set is a great way to remove duplicates in a list.
- Create a list with some duplicates:
numbers = [1, 2, 2, 3, 3, 3, 4, 4, 5]
- Use a set to remove duplicates.
- Create a new list from the set.
- Print the new list without duplicates
Conclusion and Discussion (10 minutes)
As a pair, discuss the following questions:
- What are the main differences between lists, dictionaries, and sets?
- In what situations would you prefer to use a set over a list or dictionary?
- How did working in pairs help you understand these concepts better?