

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Type Hints
incomplete
2: Basic Types
incomplete
3: Function Parameters
incomplete
4: Return Types
incomplete
5: Fixing Type Hints
incomplete
6: List and Set Hints
incomplete
7: Dictionary Hints
incomplete
8: Tuple Hints
incomplete
9: Specific Container Types
incomplete
10: Nested Types
incomplete
11: Optional Values
incomplete
12: Fix Code With Type Hints
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
We've looked at relatively simple container types like list[str], but they can get more complex when one container holds another container. That is, it's possible to have nested container types.
A dictionary, for example, could map each character's name to their list of spells:
character_spells: dict[str, list[str]] = {
"Gandalf": ["Fireball", "Light"],
"Frodo": ["Hide"],
}
We read dict[str, list[str]] from the outside in:
dict)str)list[str])In extreme cases, nested types can get super confusing, but honestly it's less confusing than it would be without the typing. For the time being, just know that type hints can describe containers within containers.