Page 1 of 1

Python: Difference in Sets

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

Code: Select all

1st_set_of _words = set((big, small, green, orange, yellow))

2nd_set_of words  = set((orange, yellow, purple, mountain, city))

difference_of_the_two_sets = 1st_set_of_words.difference(2nd_set_of_words)

# Meaning: The words found in 1st_set_of_words, but not in 2nd_set_of_words will be displayed.

print(difference_of_the_two_sets)

# {'big', 'small', 'green'} will be displayed.