DEV Community

I'm Just a Guy with a Computer
I'm Just a Guy with a Computer

Posted on

Difference of Sets in Python

The difference() method returns a set that contains the difference between two sets. The returned set contains items that exist only in the first set, and not in both sets.

Enter the below code into the interactive shell and try to execute it to see the results.

clubs  =set(["Manchester-United","Arsenal","Chelsea","Manchester-City",])

clubsb = set(["Everton","Manchester-United","Liverpool","Totehnam"])


allcubs =  clubs - clubsb
print(allcubs)

Enter fullscreen mode Exit fullscreen mode

When the above code is executed it produces the above result.

{'Chelsea', 'Arsenal', 'Manchester-City'}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more