Get startedGet started for free

Comparing Pokédexes

Two Pokémon trainers, Ash and Misty, would like to compare their individual collections of Pokémon. Let's see what Pokémon they have in common and what Pokémon Ash has that Misty does not.

Both Ash and Misty's Pokédex (their collection of Pokémon) have been loaded into your session as lists called ash_pokedex and misty_pokedex. They have been printed into the console for your convenience.

This exercise is part of the course

Writing Efficient Python Code

View Course

Exercise instructions

  • Convert both lists (ash_pokedex and misty_pokedex) to sets called ash_set and misty_set respectively.
  • Find the Pokémon that both Ash and Misty have in common using a set method.
  • Find the Pokémon that are within Ash's Pokédex but are not within Misty's Pokédex with a set method.
  • Use a set method to find the Pokémon that are unique to either Ash or Misty (i.e., the Pokémon that exist in exactly one of the Pokédexes but not both).

Hands-on interactive exercise

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

# Convert both lists to sets
ash_set = ____
misty_set = ____

# Find the Pokémon that exist in both sets
both = ____.____(____)
print(both)

# Find the Pokémon that Ash has and Misty does not have
ash_only = ____.____(____)
print(ash_only)

# Find the Pokémon that are in only one set (not both)
unique_to_set = ____.____(____)
print(unique_to_set)
Edit and Run Code