Page 1 of 1

Python: Intersection of Sets

Posted: Tue Oct 21, 2025 5:48 am
by The Jason

Code: Select all

first_set_of_words = set((red, building, brown, house, black, jacket))

second_set_of_words = set((red, house, yellow, bee, horse, jacket))

intersection_of_the_two_sets_of_words = first_set_of_words.intersection(second_set_of_words)

# Meaning: The words found in both first_set_of_words and second_set_of_words.

print(intersection_of_the_two_sets_of_words)

# {'red', 'house', 'jacket'} will be displayed