BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Writing Efficient Python Code

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • 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).

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# 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)
Kodu Düzenle ve Çalıştır