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.


open allclose all

Basic Examples  (4)

Find a key that is not present elsewhere:

Filter a list of rules:

A single element of a list remains unchanged:

A list of rules is converted to an Association:

Use a custom comparison function to compare keys:

Possible Issues  (2)

A single Rule element is automatically wrapped in a List:

These are the same as the following:

A list with no elements is not accepted:

Wolfram Research (2015), KeyComplement, Wolfram Language function,


Wolfram Research (2015), KeyComplement, Wolfram Language function,


@misc{reference.wolfram_2021_keycomplement, author="Wolfram Research", title="{KeyComplement}", year="2015", howpublished="\url{}", note=[Accessed: 03-December-2021 ]}


@online{reference.wolfram_2021_keycomplement, organization={Wolfram Research}, title={KeyComplement}, year={2015}, url={}, note=[Accessed: 03-December-2021 ]}


Wolfram Language. 2015. "KeyComplement." Wolfram Language & System Documentation Center. Wolfram Research.


Wolfram Language. (2015). KeyComplement. Wolfram Language & System Documentation Center. Retrieved from