difference

For filters.

Returns a list of unique elements in the input that are not present in the other list.

Command Type

built-in

Signature

> difference {flags} (other)

Parameters

  • other: The other list to subtract from the input.

Input/output types:

input output
list<any> list<any>
table table

Examples

Return the difference of two lists

> [1 2 3 4] | difference [3 4 5 6]
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
╰───┴───╯

Difference with duplicates in input

> [1 1 2 3] | difference [2 3]
╭───┬───╮
│ 0 │ 1 │
╰───┴───╯

Difference of two tables

> [{a:1} {a:2} {a:3}] | difference [{a:2} {a:4}]
╭───┬───╮
│ # │ a │
├───┼───┤
│ 0 │ 1 │
│ 1 │ 3 │
╰───┴───╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.