Wolfram: Extract (Get Element by Position)

By Xah Lee. Date: . Last updated: .

Get Element by Position

Extract
  • Extract[expr, position]
  • Extract[expr, {pos1, pos2, etc}]

return the part of expr at a given Position, or a list of them.

Extract[ {a,{{b,c},d},e}, {1} ]
(* a *)

Extract[ {a,{{b,c},d},e}, {2} ]
(* {{b, c}, d} *)

Extract[ {a,{{b,c},d},e}, {3} ]
(* e *)

Extract[ {a,{{b,c},d},e}, {2, 1} ]
(* {b, c} *)

Extract[ {a,{{b,c},d},e}, {2, 1, 1} ]
(* b *)

(* extract multiple items *)
Extract[ {a,{{b,c},d},e}, { {3}, {2, 1, 1} } ]
(* {e, b} *)