Chapters
Python114 chapters

Exercises

Nested Dictionaries

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

Exercise 1

Print Ada's birth year and her first field.

Python
people = {"ada": {"born": 1815, "fields": ["maths", "computing"]}}
# print the year, then the first field
Exercise 2

Look up a person who is not there, printing None instead of crashing.

Python
people = {"ada": {"born": 1815}}
# print the born value for alan, safely
Exercise 3

Group the names under their subject, creating each list as needed.

Python
pairs = [("maths", "ada"), ("maths", "grace"), ("computing", "katherine")]
groups = {}
# fill groups
print(groups)