1. Learn
  2. /
  3. Courses
  4. /
  5. Data Types in Python

Connected

Exercise

Determining set differences

Another way of comparing sets is to use the difference() method. It returns all the items found in one set but not another. It's important to remember the set you call the method on will be the one from which the items are returned. Unlike tuples, you can add() items to a set. A set will only add items that do not exist in the set.

In this exercise, you'll explore what species had male subjects in our sample, but didn't have female subjects. The set male_penguin_species has been pre-loaded into your workspace.

Instructions

100 XP
  • Use a list comprehension to iterate over each penguin in penguins saved as female_species_list:
    • If the the sex of the penguin is 'FEMALE', return the species value.
  • Create a set using the female_species_list as female_penguin_species.
  • Find the difference between female_penguin_species and male_penguin_species. Store the result as differences.
  • Print the differences. This has been done for you, so hit 'Submit Answer' to see the result!