WolframLang: Delete Element in List

By Xah Lee. Date: . Last updated: .

Delete by Index Range

Drop[ expr, n]
  • Delete n items from beginning.
  • If n is negative, delete from end.

Drop

Drop[ {1, 2, 3, 4, 5}, 2 ] === {3, 4, 5}
Drop[ {1, 2, 3, 4, 5}, -2 ] === {1, 2, 3}
Drop[ expr, {n}]

delete nth item.

Drop[ {1, 2, 3, 4, 5}, {3} ] === {1, 2, 4, 5}
Drop[ expr, {m, n}]

delete mth to nth.

Drop[ {1, 2, 3, 4, 5}, {2,4} ] === {1, 5}

Delete by Position

Delete[expr, n]

if n is a integer, same as Delete[expr, {n}]

x = {a, {{b, c}, d}, e};

Delete[ x, 1 ] === {{{b, c}, d}, e}
Delete[ x, {1} ] === {{{b, c}, d}, e}
Delete[ x, {{1}} ] === {{{b, c}, d}, e}
Delete[expr, {pos1, pos2, pos3, etc}]

Delete a list of items by Position

Delete

x = {a, {{b, c}, d}, e};

Delete[ x, {{1}} ] === {{{b, c}, d}, e}

Delete[ x, {{2}} ] === {a, e}

Delete[ x, {{1}, {2}} ] === {e}

Delete[ x, {{2, 1}} ] === {a, {d}, e}

Delete[ x, {{2, 1, 1}} ] === {a, {{c}, d}, e}

Delete by a Filtering Function

Delete Duplicates

DeleteDuplicates[expr]

Delete duplicates

DeleteDuplicates

DeleteDuplicates[ {3, x, 3, x, 4 } ] === {3, x, 4}

WolframLang List Operations