SymmetricDifference

SymmetricDifference[list1,list2,]

gives the symmetric difference of the lists listi.

Details and Options

  • SymmetricDifference[list1,list2] gives the sorted list of elements that are in list1 or list2 but not in both.
  • SymmetricDifference[list1,list2,] gives the sorted list of elements that appear in an odd number of the listi.
  • The listi must have the same head, but it need not be List.
  • SymmetricDifference[list1,list2,,SameTesttest] applies test to each pair of elements in the listi to determine whether they should be considered the same.

Examples

open allclose all

Basic Examples  (2)

Return the elements that are present in only one of the lists:

Return the elements that are present in an odd number of lists:

Scope  (1)

Use expressions with any common head:

Options  (1)

SameTest  (1)

By default, SymmetricDifference performs SameQ comparisons:

Compare numbers by numerical value with Equal:

Properties & Relations  (6)

SymmetricDifference[] returns {}:

SymmetricDifference[list,{}] returns list:

SymmetricDifference[l1,l2] returns the same elements as SymmetricDifference[l2,l1]:

SymmetricDifference[l1,l2] is equivalent to Union[Complement[l1,l2],Complement[l2,l1]]:

SymmetricDifference[l1,l2] is equivalent to Complement[Union[l1,l2],Intersection[l1,l2]]:

SymmetricDifference[l1,l2,] returns the elements that appear in an odd number of lists:

UniqueElements[{l1,l2,}] returns the elements that appear only in one of the lists:

Wolfram Research (2022), SymmetricDifference, Wolfram Language function, https://reference.wolfram.com/language/ref/SymmetricDifference.html.

Text

Wolfram Research (2022), SymmetricDifference, Wolfram Language function, https://reference.wolfram.com/language/ref/SymmetricDifference.html.

CMS

Wolfram Language. 2022. "SymmetricDifference." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SymmetricDifference.html.

APA

Wolfram Language. (2022). SymmetricDifference. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SymmetricDifference.html

BibTeX

@misc{reference.wolfram_2024_symmetricdifference, author="Wolfram Research", title="{SymmetricDifference}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/SymmetricDifference.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_symmetricdifference, organization={Wolfram Research}, title={SymmetricDifference}, year={2022}, url={https://reference.wolfram.com/language/ref/SymmetricDifference.html}, note=[Accessed: 21-November-2024 ]}