If the two set I have are:
animals = { "human", "gorilla", "fish", "parrot", "kangaroo" }
mammals = { "gorilla", "human", "kangaroo" }
What Python code could I use that would show me animals that are also mammals?
If the two set I have are:
animals = { "human", "gorilla", "fish", "parrot", "kangaroo" }
mammals = { "gorilla", "human", "kangaroo" }
What Python code could I use that would show me animals that are also mammals?
You can use python's intersection like this:
animals = { "human", "gorilla", "fish", "parrot", "kangaroo" }
mammals = { "gorilla", "human", "kangaroo" }
# Print mammals that are also animals
print(mammals.intersection(animals))
using the corresponding method:
animals.intersection(mammals)
using the shorthand for the method:
animals & mammals
both return the intersection (animals that are also mammals), so if you want to show it to the terminal you just print out the return value
print(animals & mammals)