Python: Difference in Sets

Post Reply
User avatar
The Jason
Site Admin
Posts: 888
Joined: Tue Jul 01, 2025 10:13 am
Contact:

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.
 

POSTREACT(ions) SUMMARY

Post Reply