WolframLang: Association: Filter
Truncate Association
Take[ asso, n ]
-
take first n items.
xx = Association[ a -> 1, b -> 2, c -> 3, d -> 4 ]; Take[ xx, 2 ] === <|a -> 1, b -> 2|>
Filter by Key, with List of Keys
KeyTake[asso, listOfKeys]
-
return an association containing only the elements with given keys.
xx = Association[ a -> 1, b -> 2, c -> 3, d -> 4 ]; KeyTake[ xx, {a, c} ] === <|a -> 1, c -> 3|>
KeyTake[listOfAssoc, listOfKeys]
-
gives a list of associations.
xx = { Association[ a -> 1, b -> 2, c -> 3, d -> 4 ], Association[ a -> 10, b -> 20, c -> 30, d -> 40 ] }; KeyTake[ xx, {a, c} ] (* {<|a -> 1, c -> 3|>, <|a -> 10, c -> 30|>} *)
Filter by Key, with a Function
Filter by Value, Using a Function
Select[ asso, f]
-
filter asso by function f applied to values that return true.
xx = Association[ a -> 1, b -> 2, c -> 3, d -> 4 ]; Select[ xx, EvenQ ] === <|b -> 2, d -> 4|>