WolframLang: Check Item Existence in List

By Xah Lee. Date: .
MemberQ

Check existence by Pattern

MemberQ

MemberQ[ {1, 2, 3}, 2 ] === True
MemberQ[ {1, {a, b}, 3}, {a, b} ] === True
Count

Count by Pattern

Count

Count[ {1, 2, 3, 1}, 1 ] === 2

Count[ {1, {a, b}, 3}, {a, b} ] === 1
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}}

List Operations