Lab, Dictionaries and Sets
7 tasks, easy to hard: Predict, then run, Write it, Complete it, Fix it, Trace it, Refactor it, Mini challenge. Hints come one at a time and you can see each answer. Lab work is saved as practice and earns no XP.
Open the lessonYou can read every task below. Running, checking and saving them needs a free ID.
7 tasks
Task 01 .Type what the program will print, then run it to compare.
Type exactly what this program prints. Small whole numbers in a set print in ascending order.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 02 .Solve it from the prompt, starting from an empty editor.
Given raw_ids = [101, 102, 101, 103, 104, 102], make a set unique_ids, discard 101, and print the remaining ids as a sorted list: [102, 103, 104].
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 03 .Fill the marked gaps in the starter code.
Replace each ___ with a set operator so the program prints who is in both clubs, then who is only in chess.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 04 .The starter code has a bug. Repair it so the checks pass.
This program should print each new colour once and then 3 colours, but it crashes. Fix the line that creates seen.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 05 .Fill the table with the variable values, step by step.
Each row shows n and seen each time either changes, once both exist. Small whole numbers in a set print in ascending order.
seen = set()
for n in [3, 1, 3, 2]:
seen.add(n)Sign in or create a free ID to fill in and check this table.
Task 06 .Rewrite working code to the stated rule, keeping the same output. Rule: Remove duplicates with set() instead of a loop.
This program removes duplicates with a loop and a list. Rewrite it so unique is made with set() and printed with sorted(), with no loop. The output must not change.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 07 .A short task that combines this lesson with earlier ones.
The shop's stock is a dictionary of item to quantity. Using sets made from the dictionary keys and the order, print the items that can be supplied, the items the shop does not sell, and whether the whole order can be met, so the output is:
Available: ['jam', 'tea'] Not sold: ['scone'] Complete: False
An item counts as available only if its quantity is above 0.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.