Get startedGet started for free

Using the Typing library

Type hints can be applied to collections like dictionaries and lists, hinting both the collection itself and the elements it stores. In this exercise, you'll practice exactly that. Go get 'em!

This exercise is part of the course

Intermediate Object-Oriented Programming in Python

View Course

Exercise instructions

  • Add type hints to the roster dictionary to include details about the types of keys and values.
  • Update the creation of the agents list to add type hints for both the object itself, as well as the type of the elements it stores.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Type hint the roster of codenames and number of missions
roster: ____[____, ____] = {
  "Chuck": 37,
  "Devin": 2,
  "Steven": 4
}

# Unpack the values and add type hints for the new list
agents: ____[____] = [
  f"Agent {agent}, {missions} missions" \
  for agent, missions in roster.items()
]
Edit and Run Code