Data Structures
Lists
Ordered, zero-indexed, dynamically sized, and mixed-type — a list can hold numbers, strings, other lists, and dicts together.
New to coding?
Copy the examples exactly first. Run them. Then change one number or word and run them again. You are not expected to memorize the command lists.
1
Creating and indexing
Try this code
xs = [1, 2, 3, 4, 5];
xs[0] // 1
xs[0] = 99; // in-place index assignment
grid = [[1, 2], [3, 4]];
grid[0][1] = 42; // chained index assignment works too2
Mutation
push and pop mutate the list in place.
Try this code
xs = [1, 2, 3];
push(xs, 4); // [1, 2, 3, 4]
last_val = pop(xs); // removes & returns 43
Concatenation & slicing
+ builds a new list; slice takes a sub-range (end exclusive).
Try this code
combined = [0] + xs;
part = slice([1,2,3,4,5], 1, 4); // [2, 3, 4]4
Common methods
Try this code
len(xs) // length
first(xs) // first element
last(xs) // last element
reverse(xs) // reversed copy
has(xs, 3) // membership test5
Higher-order functions
Try this code
map(xs, fn(x) => x * x);
filter(xs, fn(x) => x > 2);
reduce(xs, fn(a,b) => a + b, 0);
sort_by(xs, fn(x) => x);
any(xs, fn(x) => x > 4);
all(xs, fn(x) => x > 0);