union()

Read(262) Label: union,

Here’s how to use union() function.

A .union()

Description:

Compute the union of members in a sequence whose members are sequences.

Synatax:

 A.union()

Note:

The function computes the union of members in sequence A whose members are sequences so as to get a sequence in which identical members won’t appear repeatedly. Duplicate members in the same sub-sequence will be retained. 

Parameters:

A

A sequence whose members are sequences

Return value:

A new sequence created through the union of members of sequence A

Example:

 

A

 

1

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

[1,2,3,4,5,7,8] “3” only appears once

2

=[[1,2,2],[3,4,4],4].union()

[1,2,2,3,4,4] The duplicate “4” is stripped out. Identical members in the same sub-sequence are not regarded as duplicate ones

3

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

[1,2,2,2,3] There are three “2s” in the second sub-sequence, so the final result also include three “2s”

Related functions:

A.conj()

A.diff()

A.isect()

A.xunion()

A .union( x )

Description:

Compute x with each member of the sequence whose members are sequences, and then perform union operation on members of the new sequence.

Synatax:

 A.union(x)

Note:

The function loops through sequence A, whose members are sequences, to compute expression x and then performs union operation on members of the resulting sequence.

Parameters:

A

A sequence whose members are sequences

x

An expression that returns a sequence

Return value:

A sequence created through the union of new members of sequence A

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].union(~.(NAME))

[Rebecca,Ashley,…] Common members of A1 and A2 only appear once, and identical members in the same sub-sequence are not regarded as duplicate ones

Related functions:

A.union()