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.
Deze oefening maakt deel uit van de cursus
Data Types in Python
Oefeninstructies
- Combine all the species in
female_penguin_speciesandmale_penguin_speciesby computing their union. Store the result asall_species. - Print the number of species in
all_species. You can use thelen()function to compute the number of species inall_species. - Find all the species that occur in both
female_penguin_speciesandmale_penguin_speciesby computing their intersection. Store the result asoverlapping_species. - Print the number of species in
overlapping_species.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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(____)