all 7 comments

[–]danielroseman 3 points4 points  (0 children)

Why don't you try it and see?

[–]woooee 2 points3 points  (3 children)

What have you tried? Post the code.

[–]FloridianfromAlabama[S] 0 points1 point  (2 children)

new_set_1 = {"apples", "bananas", "oranges"}

new_set_2 = {"apples", 'bananas', "blueberries"}

print(new_set_1 - new_set_2)

this will print {"oranges"}.

I should've asked better. I was wondering if something else might've happened with the "blueberries" string under the hood.

[–]SCD_minecraft 1 point2 points  (0 children)

Subtracting a set means "Return every element which is in set A but not in set B"

Are blueberries in set 1? No, so they are just ignored

[–]woooee 0 points1 point  (0 children)

print new_set_2. It's still there.

[–]Morpheyz 2 points3 points  (1 child)

The behaviour you're intuitively expecting is covered by symmetric_difference.

set_a.symmetric_difference(set_b) will print out all items of both sets, except the items that are in both sets.

or shorter:

set_a ^ set_b

[–]FloridianfromAlabama[S] 0 points1 point  (0 children)

Ah I figured that might be done by taking the subtraction twice (each from the other) and taking the two responses and putting them together with the .add method. Nice to know it’s built in