Wolfram Language & System 10.4 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

KeyValuePattern

KeyValuePattern[{patt1,}]
is a pattern object that represents an association or list of rules that includes elements matching each of the .

DetailsDetails

  • The are often of the form but can be any pattern.
  • Elements matching the can appear in any order in the association or list of rules.
  • The are matched in the order they appear.
  • Each of the is taken to match a different element of the association or list of rules.
  • For a single pattern patt, KeyValuePattern[patt] is equivalent to KeyValuePattern[{patt}].
  • KeyValuePattern[{}] matches any association or list of rules.

ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

KeyValuePattern lets you match any element in an association:

In[1]:=
Click for copyable input
Out[1]=

It also works on lists of rules:

In[2]:=
Click for copyable input

KeyValuePattern matches elements that appear anywhere in an association:

In[1]:=
Click for copyable input
Out[1]=

Match any association with two entries:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 2016
(10.4)