KeyDrop
Details
- KeyDrop preserves the original order of elements.
- Any keyi that does not appear in assoc is ignored.
- KeyDrop can be applied not only to Association objects, but also to lists of rules. It can also be applied to lists of associations and lists of lists of rules, as well as Tabular and Dataset objects.
- KeyDrop[keys][expr] is equivalent to KeyDrop[expr,keys].
Examples
open all close allBasic Examples (4)
Delete entry with the specified key from association:
KeyDrop[<|a -> 1, b -> 2|>, a]Delete entries, given a list of keys:
KeyDrop[<|a -> 1, b -> 2, c -> 3, d -> 4|>, {a, d}]Delete entries from several associations, given a list of keys:
KeyDrop[{<|a -> 1, b -> 2|>, <|c -> 3, d -> 4|>}, {a, d}]Use the operator form of KeyDrop:
KeyDrop[{a, d}][<|a -> 1, b -> 2, c -> 3, d -> 4|>]Scope (20)
Delete entries from a list of rules, given a key:
KeyDrop[{a -> 1, b -> 2}, a]Delete entries from several lists:
KeyDrop[{{a -> 1, b -> 2}, {b -> 3}}, {b}]Delete from a mixed list of an association and a list of rules:
KeyDrop[{<|a -> 1, b -> 2|>, {b -> 3, c -> 3}}, b]Association (6)
Drop the key-value pairs of an association that have the given keys:
KeyDrop[<|"a" -> α, "b" -> β, "c" -> γ|>, {"a", "c"}]Drop a single key-value pair from an association:
KeyDrop[<|"a" -> 10, "b" -> 20, "c" -> 30|>, {"b"}]Equivalently, give the key directly:
KeyDrop[<|"a" -> 10, "b" -> 20, "c" -> 30|>, "b"]Keys not present in the association will be ignored:
KeyDrop[<|"a" -> α, "b" -> β|>, {"a", "d"}]KeyDrop[<|"a" -> α, "b" -> β|>, "d"]KeyDrop[<|"a" -> 1.5, "b" -> 2.7, "c" -> 3.4|>, {}]Use the operator form of KeyDrop:
KeyDrop[{"a", "c"}][<|"a" -> α, "b" -> β, "c" -> γ|>]KeyDrop["b"][<|"a" -> α, "b" -> β, "c" -> γ|>]Drop key-value pairs from several associations in a list:
assocs = {<|"a" -> A1, "b" -> B1, "c" -> C1|>, <|"a" -> A2, "b" -> B2, "d" -> D2|>};KeyDrop[assocs, {"a", "c"}]This is equivalent to mapping over the list of associations:
Map[KeyDrop[{"a", "c"}], assocs]List of Rules (7)
Drop the rules having the given keys:
KeyDrop[{"a" -> α, "b" -> β, "c" -> γ}, {"a", "c"}]Drop a single rule from a list of rules:
KeyDrop[{"a" -> 10, "b" -> 20, "c" -> 30}, {"b"}]Equivalently, give the key directly:
KeyDrop[{"a" -> 10, "b" -> 20, "c" -> 30}, "b"]Keys not present in the list of rules will be ignored:
KeyDrop[{"a" -> α, "b" -> β}, {"a", "d"}]KeyDrop[{"a" -> α, "b" -> β}, "d"]KeyDrop[{"a" -> 1.5, "b" -> 2.7, "c" -> 3.4}, {}]Use the operator form of KeyDrop:
KeyDrop[{"a", "c"}][{"a" -> α, "b" -> β, "c" -> γ}]KeyDrop["b"][{"a" -> α, "b" -> β, "c" -> γ}]Drop rules from several lists of rules:
lists = {{"a" -> A1, "b" -> B1, "c" -> C1}, {"a" -> A2, "b" -> B2, "d" -> D2}};KeyDrop[lists, {"a", "c"}]This is equivalent to mapping over the list of lists of rules:
Map[KeyDrop[{"a", "c"}], lists]KeyDrop can act on lists containing both associations and lists of rules, returning a list of associations:
data = {<|"a" -> A1, "b" -> B1, "c" -> C1|>, {"a" -> A2, "b" -> B2}};KeyDrop[data, {"a", "c"}]Tabular (2)
This is a Tabular object with three columns:
tab = Tabular[{{1, 11, True}, {2, 11, False}, {3, 13, False}}, {"a", "b", "c"}]Form another Tabular object by dropping the specified columns:
KeyDrop[tab, {"a", "c"}]KeyDrop[tab, "b"]Drop all columns, returning a result with zero columns:
KeyDrop[tab, {"a", "b", "c"}]%//NormalConstruct a Tabular object with extended column keys:
tab = Tabular[{{1, 11, True, False}, {2, 11, False, True}, {3, 13, False, False}}, {ExtendedKey["int", "a"], ExtendedKey["int", "b"], ExtendedKey["bool", "a"], ExtendedKey["bool", "c"]}]KeyDrop[tab, {ExtendedKey["int", "a"], ExtendedKey["bool", "a"]}]The key "c" uniquely identifies a column:
KeyDrop[tab, "c"]The key "a" does not uniquely identify a column, and therefore no column is dropped:
KeyDrop[tab, "a"]Dataset (2)
Take a Dataset object of depth 2 with three columns:
ds = Dataset[{<|"a" -> 1, "b" -> 11, "c" -> True|>, <|"a" -> 2, "b" -> 11, "c" -> False|>, <|"a" -> 3, "b" -> 13, "c" -> False|>}]Construct another Dataset object by dropping the specified columns:
KeyDrop[ds, {"a", "c"}]KeyDrop[ds, "b"]Drop all columns, returning a result with zero columns:
KeyDrop[ds, {"a", "b", "c"}]%//NormalKeyDrop can act on Dataset objects of depth 1 whose normal form is an association:
Dataset[<|"a" -> α, "b" -> β, "c" -> γ|>]KeyDrop[%, {"a", "c"}]Properties & Relations (3)
KeyDrop preserves the original order of elements:
KeyDrop[<|d -> 4, c -> 3, b -> 2, a -> 1|>, {a, c}]KeyDrop[<|a -> 1, b -> 2, c -> 3, d -> 4|>, {a, c}]KeyTake returns a result with the given keys:
KeyTake[<|a -> 1, b -> 2, c -> 3|>, {a, b}]KeyDrop returns a result with all other keys:
KeyDrop[<|a -> 1, b -> 2, c -> 3|>, {a, b}]KeyDropFrom[x,keys] is equivalent to x=KeyDrop[x,keys], hence changing the variable of x:
x = <|a -> 1, b -> 2, c -> 3, d -> 4|>;KeyDrop[x, {b, d}]xKeyDropFrom[x, {b, d}]xRelated Guides
Text
Wolfram Research (2014), KeyDrop, Wolfram Language function, https://reference.wolfram.com/language/ref/KeyDrop.html (updated 2025).
CMS
Wolfram Language. 2014. "KeyDrop." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/KeyDrop.html.
APA
Wolfram Language. (2014). KeyDrop. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/KeyDrop.html
BibTeX
@misc{reference.wolfram_2026_keydrop, author="Wolfram Research", title="{KeyDrop}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/KeyDrop.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_keydrop, organization={Wolfram Research}, title={KeyDrop}, year={2025}, url={https://reference.wolfram.com/language/ref/KeyDrop.html}, note=[Accessed: 13-June-2026]}