Wolfram: Association. Delete Items by Key
Delete by Key
KeyDrop-
KeyDrop[asso, key]KeyDrop[asso, listOfKeys]KeyDrop[listOfAsso, key]
return a new association with some keys removed. (does not modify variable)
KeyDrop[ Association[ a -> 1, b -> 2, c -> 3 ], b ] (* <|a -> 1, c -> 3|> *) KeyDrop[ Association[ a -> 1, b -> 2, c -> 3 ], {c, b} ] (* <|a -> 1|> *) KeyDrop[ {Association[ a -> 1, b -> 2, c -> 3 ], Association[ a -> 11, b -> 22 ]}, b ] (* {<|a -> 1, c -> 3|>, <|a -> 11|>} *)
Association Variable, Delete by Key, Modify Variable
KeyDropFrom[assoVar, key]-
- remove the element with the specified key.
- modify the variable.
- return the new value of the variable.
xx = Association[ a -> 1, b -> 2]; KeyDropFrom[ xx, b ] (* <|a -> 1|> *) xx (* <|a -> 1|> *) KeyDropFrom[assoVar, listOfKeys]-
remove multiple elements.
xx = Association[ a -> 1, b -> 2, c -> 3, d -> 4]; KeyDropFrom[ xx, {a, c} ] (* <|b -> 2, d -> 4|> *)