WolframLang: Get Parts of List
Get Element by Position
Extract
Get Parts by Index
Part[expr, i]
-
🔸 SHORT SYNTAX:
expr[[i]]
ith part of expr. If i is negative, count from right.
Part[{a, b, c, {d1, d2}, e}, 2] (* b *) (* short syntax *) {a, b, c, {d1, d2}, e}[[2]] (* b *) (* count from right *) {a, b, c, {d1, d2}, e}[[-2]] (* {d1, d2} *)
Part[expr, {a, b, c}]
-
🔸 SHORT SYNTAX:
expr[[{a, b, c}]]
Same as
{ Part[expr, a], Part[expr, b], Part[expr, c] }
{a, b, c, {d1, d2}, e}[[{2,-1}]] (* {b, e} *)
Part[expr, a, b, c]
-
🔸 SHORT SYNTAX:
expr[[a, b, c]]
same as
Part[Part[Part[expr, a], b], c]
{a, b, c, {d1, d2}, e}[[4,1]] (* d1 *)
Part[expr, m;;n]
-
🔸 SHORT SYNTAX:
expr[[m;;n]]
(note:
a;;b
is short forSpan[a, b]
)parts m through n. If m is omitted, default to beginning. If n is omitted, default to end.
{a, b, c, {d1, d2}, e}[[2;;4]] (* {b, c, {d1, d2}} *)
expr[[m;;]]
→ part m to endexpr[[;;n]]
→ beginning to nexpr[[;;,j]]
→ column jexpr[[m1;;n1, m2;;n2]]
→ submatrix
(* column 1 *) {{a,b}, {c,d}}[[;;,1]] (* {a, c} *)
Get Items by Range of Index
Other List Extraction Functions (by index)
Get Elements by Function or Pattern
WolframLang List Operations
- WolframLang: List Operations
- WolframLang: Get Parts of List
- WolframLang: Add Element to List
- WolframLang: Delete Element in List
- WolframLang: Change Element in List
- WolframLang: Check Item Exist in List
- WolframLang: Filter List
- WolframLang: Sort, Reverse, Order
- WolframLang: List Reshape (split, group, flatten, transpose)
- WolframLang: List Combinatorics
- WolframLang: List Join, Union, Intersection, Difference