

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 covered hints for basic types like str, int, float, and bool, but you can also add hints for container types: types that hold other values. For example:
list: mutable sequence of valuesset: unordered collection of unique valuesdict: collection of key-value pairstuple: immutable sequence of valuesWhen we type-hint a container, we specify what kind of container it is and what type of values it contains. For example, a list of strings can be expressed as list[str]:
inventory: list[str] = ["Iron Sword", "Healing Potion"]
The "contained" type goes in square brackets after the container type. Similarly, for a set of strings, we would write set[str]:
unique_items: set[str] = {"Iron Sword", "Healing Potion"}
Fantasy Quest has a function that removes duplicate item names from a character's inventory. It works correctly but lacks annotation. Add type hints to get_unique_items.
Don't change the function body.