WolframLang: Misc List Operations

By Xah Lee. Date: . Last updated: .

Check Existence

MemberQ
Check existence by Pattern

MemberQ

Count
Count by Pattern

Count

Get the Position of a Element

Position[expr, pattern]
Return a list of positions that Pattern occur in expression. If not exist, return a empty list.

Position

xx = {a, {{b, c}, a}, e};

(* position of e is {3} *)
Position[ xx, e ] === {{3}}

(* position of a is {1} and {2, 2} *)
Position[ xx, a ] === {{1}, {2, 2}}

(* when not found, empty list *)
Position[ xx, m ] === {}

(* position of b *)
Position[ xx, b ] === {{2, 1, 1}}

(* position of {b, c} *)
Position[ xx, {b, c} ] === {{2, 1}}

Group into Sublists

Partition
group every n items into sublist.

Partition

x = Range[ 8 ];
Partition[ x, 2 ] === {{1, 2}, {3, 4}, {5, 6}, {7, 8}}

order

Sort

Sort

SortBy

SortBy

reverse

reverse

Ordering
return a list of integers that represent the ordering of the items.

Ordering

Ordering[ {a, c, b} ] === {1, 3, 2}
RotateRight
shift all elements to the right, last item is moved to first.

RotateRight

RotateRight[ {1, 2, 3, 4} ] === {4, 1, 2, 3}
RotateLeft
shift all elements to the left, first item is moved to last.

RotateLeft

Other Functions on List

Join
concatenate lists Join
Union
union of sets Union
Intersection
intersection of sets Intersection
Complement
subtract a set from other sets Complement
Subsets
all possible subsets Subsets
Riffle
Riffle
Partition
Partition
Split
Split
SplitBy
SplitBy
Gather
Gather
GatherBy
GatherBy
Tuples
Tuples
Permutations
Permutations
Min
Min
Max
Max
Flatten
Flatten
Transpose
Transpose
PadLeft
PadLeft

List