Skip to content
CCC Python Course

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

  1. 1Tuples, dictionaries and sets

Practice

Try these on the judges. Each link opens the problem on WMOJ or DMOJ.

  1. 2023 J2
    Chili Peppers (opens on WMOJ in a new tab) WMOJ

    Look up each order's cost from a lookup table of prices.

  2. 2022 J4
    Good 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.

  3. 2014 J5
    Assigning 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.