Wolfram: Association. Delete Items by Index

By Xah Lee. Date: . Last updated: .

Get Items by Index or Index Range

Take
  • Take[ asso, n ] → first n items.
  • Take[ asso, -n ] → last n items.
  • Take[ asso, {n} ] → nth item.
  • Take[ asso, {m,n} ] → m to n.
Take[ Association[ a -> 1, b -> 2, c -> 3, d -> 4 ], 2 ]
(* <|a -> 1, b -> 2|> *)

Delete Items by Index or Index Range

Drop
  • Drop[ asso, n ] → remove first n items.
  • Drop[ asso, -n ] → remove last n items.
  • Drop[ asso, {n} ] → remove nth item.
  • Drop[ asso, {m,n} ] → remove m to n.
Drop[ Association[ a -> 1, b -> 2, c -> 3, d -> 4 ], 2 ]
(* <|c -> 3, d -> 4|> *)
Delete
  • Delete[ asso, n ] → remove nth item.
  • Delete[ asso, Key[ b ] ] → remove item of key b
(* delete at index 2 *)
Delete[ Association[ a -> 1, b -> 2, c -> 3, d -> 4 ], 2 ]
(* <|a -> 1, c -> 3, d -> 4|> *)
(* delete key b *)
Delete[ Association[ a -> 1, b -> 2, c -> 3, d -> 4 ], Key[ b ] ]
(* <|a -> 1, c -> 3, d -> 4|> *)

Wolfram. Association (Key Value List)