Wolfram: Association. Delete Items by Filter
Filter by Key, via List of Keys
KeyTake[asso, listOfKeys]-
return an association containing only the elements with given keys.
KeyTake[ Association[ a -> 1, b -> 2, c -> 3, d -> 4 ], {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, via a Function
Filter by Values, via a Function
Select-
Select[ asso, f]→ get items where f return true on the values.Select[ asso, f, n]→ get first n.
Select[ Association[ a -> 1, b -> 2, c -> 3, d -> 4 ], EvenQ ] (* <|b -> 2, d -> 4|> *)