WOLFRAM

KeyComplement
Copy to clipboard.
KeyComplement

Copy to clipboard.
KeyComplement[{assocall,assoc1,assoc2,}]

generates an association in which only elements whose keys appear in assocall but not in any of the associ are retained.

Details and Options

  • KeyComplement preserves the order of the elements in assocall.
  • KeyComplement can be used not only on Association objects, but also on lists of rules.
  • KeyComplement[{assocall, assoc1, }, SameTesttest] applies test to each pair of keys of the elements in assocall and the associ to determine whether they should be considered the same.

Examples

open allclose all

Basic Examples  (4)Summary of the most common use cases

Find a key that is not present elsewhere:

Out[1]=1
Out[2]=2
Out[3]=3

Filter a list of rules:

Out[1]=1

A single element of a list remains unchanged:

Out[1]=1

A list of rules is converted to an Association:

Out[2]=2

Use a custom comparison function to compare keys:

Out[1]=1

Possible Issues  (2)Common pitfalls and unexpected behavior

A single Rule element is automatically wrapped in a List:

Out[1]=1
Out[2]=2

These are the same as the following:

Out[3]=3

A list with no elements is not accepted:

Out[1]=1
Wolfram Research (2015), KeyComplement, Wolfram Language function, https://reference.wolfram.com/language/ref/KeyComplement.html.
Copy to clipboard.
Wolfram Research (2015), KeyComplement, Wolfram Language function, https://reference.wolfram.com/language/ref/KeyComplement.html.

Text

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

Copy to clipboard.
Wolfram Research (2015), KeyComplement, Wolfram Language function, https://reference.wolfram.com/language/ref/KeyComplement.html.

CMS

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

Copy to clipboard.
Wolfram Language. 2015. "KeyComplement." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/KeyComplement.html.

APA

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

Copy to clipboard.
Wolfram Language. (2015). KeyComplement. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/KeyComplement.html

BibTeX

@misc{reference.wolfram_2025_keycomplement, author="Wolfram Research", title="{KeyComplement}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/KeyComplement.html}", note=[Accessed: 26-March-2025 ]}

Copy to clipboard.
@misc{reference.wolfram_2025_keycomplement, author="Wolfram Research", title="{KeyComplement}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/KeyComplement.html}", note=[Accessed: 26-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_keycomplement, organization={Wolfram Research}, title={KeyComplement}, year={2015}, url={https://reference.wolfram.com/language/ref/KeyComplement.html}, note=[Accessed: 26-March-2025 ]}

Copy to clipboard.
@online{reference.wolfram_2025_keycomplement, organization={Wolfram Research}, title={KeyComplement}, year={2015}, url={https://reference.wolfram.com/language/ref/KeyComplement.html}, note=[Accessed: 26-March-2025 ]}