Chapters
Python114 chapters

Exercises

Dictionary Methods

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Group each name under its subject, creating the list when the subject is new.

Python
pairs = [("maths", "ada"), ("maths", "grace"), ("code", "kat")]
groups = {}
# fill groups
print(groups)
Exercise 2

This raises because the view is live. Fix it so the low scores are removed.

Python
scores = {"a": 1, "b": 5, "c": 2}

for key in scores:
    if scores[key] < 3:
        del scores[key]

print(scores)
Exercise 3

Merge the custom settings over the defaults, leaving both originals unchanged.

Python
defaults = {"colour": "black", "size": 10}
custom = {"size": 12}
# print the merged result, then the untouched defaults