KeyTake

KeyTake[assoc,{key1,key2,}]
yields an association containing only the elements with keys .

KeyTake[{assoc1,assoc2,},keys]
gives a list of associations.

KeyTake[{key1,key2,}]
represents an operator form of KeyTake that can be applied to an expression.

DetailsDetails

  • KeyTake[assoc,] gives an Association object whose elements are in the order of the .
  • Any that does not appear in assoc is ignored.
  • KeyTake can be applied not only to Association objects, but also to lists of rules.
  • is equivalent to KeyTake[keys,expr].

ExamplesExamplesopen allclose all

Basic Examples  (7)Basic Examples  (7)

Select rules from an association, given a list of keys:

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

Select from several associations, given a list of keys:

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

Select rules from a list, given keys:

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

Select rules from several lists:

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

Select from an association, using a single key:

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

Select from a list, using a single key:

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

Use the operator form of KeyTake:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 2014
(10.0)