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

Finding all the data and the overlapping data between sets

Sets have several methods to combine, compare, and study them all based on mathematical set theory. The .union() method returns a set of all the elements found in the set you used the method on plus any sets passed as arguments to the method. You can also look for overlapping data in sets by using the .intersection() method on a set and passing another set as an argument. It will return an empty set if nothing matches.

Your job in this exercise is to find the union and intersection in the species from male and female penguins. For this purpose, two sets have been pre-loaded into your workspace: female_penguin_species and male_penguin_species.

Bu egzersiz

Data Types in Python

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

Egzersiz talimatları

  • Combine all the species in female_penguin_species and male_penguin_species by computing their union. Store the result as all_species.
  • Print the number of species in all_species. You can use the len() function to compute the number of species in all_species.
  • Find all the species that occur in both female_penguin_species and male_penguin_species by computing their intersection. Store the result as overlapping_species.
  • Print the number of species in overlapping_species.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Find the union: all_species
all_species = ____

# Print the count of names in all_species
print(____)

# Find the intersection: overlapping_species
overlapping_species = ____

# Print the count of species in overlapping_species
print(____)
Kodu Düzenle ve Çalıştır