# Make `set.symmetric_difference()` take any number of arguments

The following methods of `set` can accept a variable number of arguments:

• `union(*others)`
• `update(*others)`
• `intersection(*others)`
• `intersection_update(*others)`
• `difference(*others)`
• `difference_update(*others)`

However, the `symmetric_difference()` and `symmetric_difference_update()` methods accept only a single variable:

• `symmetric_difference(others)`
• `symmetric_difference_update(others)`

I don’t think there will be a problem if we make `symmetric_difference()` and `symmetric_difference_update()` similar to other methods, i.e.

• `symmetric_difference(*others)`
• `symmetric_difference_update(*others)`
1 Like

What’s the symmetric difference between one set and two others?

For example, `a.symmetric_difference(b, c)` would be equivalent to `a ^ b ^ c`. Given that symmetric difference is commutative, the order does not matter.

1 Like

Sorry for the mistake. The symmetric difference operation is actually commutative and associative.

Mathematically you’re spot on. That’s a perfectly rigourous, well defined argument.

But I wonder if the current restriction forces the writing of clearer code, and clearer expression of intent?

How many Python users in 2024, intuitively expect the intersection of n sets to be included in the symmetric difference of the same n sets, only when n is odd?

How many users would use `set.symmetric_difference(*others)` in the first place? I don’t know that the somewhat unintuitive behavior of this operation is that strong a case against it.

People who are using `symmetric_difference` should know what they want (and the documentation should be clear about what will happen), and that’s the best we can hope for.

I was pretty sure this has been discussed before, and I can’t remember the outcome of that discussion. edit I was thinking of a different discussion, about adding symmetric_difference to dictionaries, which is a much more confusing operation.

For whatever reason I definitely didn’t think `^` was associative and commutative…given that it is, it seems reasonable to allow multiple arguments in the methods. But there might be a reason I’m missing.