17.2 Nested Dictionaries

From Foundations of Python ProgrammingGNU FDL 1.3Original pagePython1 class period1 exercise1 graded test

README.md

17.2 Nested Dictionaries

Just as lists can contain items of any type, the value associated with a key in a dictionary can also be an object of any type. In particular, it is often useful to have a list or a dictionary as a value in a dictionary. And of course, those lists or dictionaries can also contain lists and dictionaries. There can be many layers of nesting.

Only the values in dictionaries can be objects of arbitrary type. The keys in dictionaries must be one of the immutable data types (numbers, strings, tuples).

Check Your Understanding

Check your understanding: a multiple-choice question in the book.

Exercise 1

1. Extract the value associated with the key color and assign it to the variable color. Do not hard code this.

Open the 01 folder and edit main.py. Run Tests checks it.

For teachers

17.2 Nested Dictionaries

Students read Foundations of Python Programming's “Nested Dictionaries” in CS Room and work through its 1 Python coding exercise (1 graded).

  • Time: 1 class period
  • Tests: 1 in 1 graded exercise, set up for you when you import the lesson

Exercises

FolderGradingTests
01Autograded1