Tuples, dictionaries and sets
- Stage
- 1
- Module
- M1.9
- Lessons
- 1
In this module
- Pair values together with a tuple literal, and convert a sequence to one with
tuple(). - Look up and store values by key with a dict, including a dict comprehension.
- Test membership and remove duplicates with a set, including a set comprehension.
- Count how many times each value appears with a dict, using
.get()for a default.
Before this module
Lessons
Practice
Try these on the judges. Each link opens the problem on WMOJ or DMOJ.
- 2023 J2Chili Peppers (opens on WMOJ in a new tab) WMOJ
Look up each order's cost from a lookup table of prices.
- 2022 J4Good Groups (opens on WMOJ in a new tab) WMOJ(same problem as 2022 S2)
Check a small set of grouping rules against a list of student groups, on the smallest test cases.
- 2014 J5Assigning Partners (opens on DMOJ in a new tab) DMOJ(same problem as 2014 S2)
Assign each name in one list to a role from another list, and answer questions about the pairing.
Why DMOJ: Tries the same kind of problem on DMOJ, which holds 2014 to 2020.