Wolfram: List. Get Parts
Get Element by Position
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
Take
-
take nth to mth item
(* basic examples of Take *) (* First 3 *) Take[{1, 2, 3, 4, 5, 6, 7, 8, 9}, 3] (* {1, 2, 3} *) (* last 3 *) Take[{1, 2, 3, 4, 5, 6, 7, 8, 9},-3] (* {7, 8, 9} *) (* m to n *) Take[{1, 2, 3, 4, 5, 6, 7, 8, 9}, {3,5}] (* {3, 4, 5} *)
Drop
-
Return a list with nth to mth dropped
Other List Extraction by Index Functions
Wolfram. List Operations
- Wolfram: List Operations
- Wolfram: List. Create (Table)
- Wolfram: Create Flat List (Range)
- Wolfram: List. Get Parts
- Wolfram: List. Add Element
- Wolfram: List. Delete Element
- Wolfram: List. Change Element
- Wolfram: List. Check Exist
- Wolfram: List. Filter
- Wolfram: List. Sort Reverse Order
- Wolfram: List. Reshape (split, group, flatten, transpose)
- Wolfram: List. Count, Group, Similar Items
- Wolfram: List. Combinatorics
- Wolfram: List. Join, Union, Intersection, Difference