We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Dictionary Hints

Dictionaries are container types too, but they map keys to values, so their type hints include both:

item_counts: dict[str, int] = {
    "Wooden Arrow": 30,
    "Small Amethyst": 2,
}

The first type is for the keys; the second is for the values.

dict[key_type, value_type]

So dict[str, int] means:

  • The keys are strings
  • The values are integers

Not all types can be used as dictionary keys. The key types that you'll see most often are strings and integers. Dictionary values, on the other hand, can be any type.

Assignment

Fantasy Quest also tracks how many of each item a character has in their inventory. Add type hints to the get_item_count function.

Don't change the function body.