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

Counting Practice

Checking for Existence

If you're unsure whether a key exists in a dictionary, use the in keyword.

cars = {"ford": "f150", "toyota": "camry"}

print("ford" in cars)
# Prints: True

print("gmc" in cars)
# Prints: False

Assignment

We need to report how many enemies are in our players immediate vicinity – but they want to know what those enemies are! Fix the count_enemies function. It accepts as input:

  • enemy_names: a list of strings

It should return a dictionary where:

  • The keys are all the enemy names from the list
  • The values are the number of times each enemy appeared in the list