diff()

Read(208) Label: diff,

Here’s how to use diff() function.

A .diff()

Description:

Generate a new sequence by removing from the first sub-sequence of a sequence the members that exist in the other sub-sequences of the sequence.

Syntax:

A .diff()

Note:

Generally sequence A contains multiple sub-sequences. The function creates a new sequence by getting the difference of A’s first sub-sequence and the other sub-sequences, ensuring that the new sequence doesn’t include any member of the other sub-sequences.

The algorithm is to compute the difference between the first sub-sequence and the second one, then compute the difference between the result and the third sub-sequence, and so on and so forth.

Parameters:

A

A sequence whose members are sequences

Return value:

A new sequence created by performing difference operations on A’s first sub-sequence and the other sub-sequences.

Example:

 

A

 

1

=[[1,2,3,4,5],[3,7,8]].diff()

[1,2,4,5]

2

=[[1,2,3],[3,2],1].diff()

[]

3

=[[1,2,2,3],2].diff()

[1,2,3] remove only one of the duplicate members

4

=demo.query("select top 2 * from EMPLOYEE")

5

=demo.query("select top 1 * from EMPLOYEE")

6

=[A4,A5].diff()

Since A4 and A5 come from different table sequences and have different store addresses, so the same records are regarded as different members

Note:

If the sub-sequences are record sequences, we can judge if they are duplicate by their store addresses.

Related functions:

A.diff(x)

A.union()

A.conj()

A.isect()

A.xunion()

A .diff( x )

Description:

Generate a sequence by first performing a certain computation on a given sequence and then removing from the resulting sequence’s first sub-sequence the members that exist in the other sub-sequences.

Syntax:

A.diff(x)

Note:

Generally sequence A contains multiple sub-sequences. The function loops through each sub-sequence of A to compute expression x and get the difference of the resulting sequence’s first sub-sequence and the other sub-sequences, ensuring that the difference result doesn’t include any member of the other sub-sequences.

The algorithm is to compute the difference between the first sub-sequence and the second one, then compute the difference between the result and the third sub-sequence, and so on and so forth.

Parameters:

A

A sequence whose members are sequences

x

An expression that returns a sequence

Return value:

  A sequence

Example:

 

A

 

1

=demo.query("select * from EMPLOYEE where GENDER = 'M' order by NAME")

 

2

=demo.query("select * from EMPLOYEE where GENDER = 'F' order by NAME")

 

3

=[A1,A2].diff(~.(NAME))

Remove only one of the duplicate members

Related functions:

A.diff()