Skip to content

Instantly share code, notes, and snippets.

@raeq
Created May 3, 2020 12:43
Show Gist options
  • Save raeq/567065a3a92fbc317af71a4537e4498d to your computer and use it in GitHub Desktop.
Save raeq/567065a3a92fbc317af71a4537e4498d to your computer and use it in GitHub Desktop.
Working with Sets
citrusfruit:set = {"oranges", "lemons", "limes", "satsumas", "nectarines"}
treefruit:set = {"apples", "pears", "cherries", "plums", "peaches", "plums", "cherries", "oranges", "lemons", "limes"}
stonefruit:set = {"cherries", "plums", "peaches", "nectarines"}
#tree fruit with stones
print(treefruit.intersection(stonefruit))
#tree fruit which are citrus
print(treefruit.intersection(citrusfruit))
#citrus fruit with stones
print(citrusfruit.intersection(stonefruit))
#all stone and all tree fruits
print(stonefruit.union(treefruit))
#all fruit except citrus fruit
print(stonefruit.union(treefruit).difference(citrusfruit))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment