Created
May 3, 2020 12:43
-
-
Save raeq/567065a3a92fbc317af71a4537e4498d to your computer and use it in GitHub Desktop.
Working with Sets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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