allEqual
returns bool
allEqual(items: list<int>) -> boolallEqual(items: list<string>) -> bool
True when every item in the list is the same value — and true for empty and single lists, which have nothing to disagree.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to check |
Example
if allEqual(repeated(5, 3)) { print("uniform") }
if allEqual(menuOptions()) { print("uniform") }
append
returns list<int> or list<string> or list<tile> or list<bag>
append(items: list<int>, value: int) -> list<int>append(items: list<string>, value: string) -> list<string>append(items: list<tile>, value: tile) -> list<tile>append(items: list<bag>, value: bag) -> list<bag>
A new list with the value added on the end. The list is a value, so this answers a new one rather than changing the old: xs = append(xs, v).
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to add to |
| valuerequired |
int |
the item to put on the end |
Example
print("longer", count(append(range(0, 5), 9)))
print("longer", count(append(menuOptions(), "x")))
print("longer", count(append(path(myTile()), myTile())))
print("longer", count(append(bagList(), newBag())))
clampAll
returns list<int>
clampAll(items: list<int>, low: int, high: int) -> list<int>
Every number in a list clamped between two bounds — one call instead of a loop. Refuses low above high.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to bound |
| lowrequired |
int |
the smallest a number may stay |
| highrequired |
int |
the largest a number may stay |
Example
print(first(clampAll(range(0, 5), 2, 3)))
concat
returns list<int> or list<string> or list<tile> or list<bag>
concat(a: list<int>, b: list<int>) -> list<int>concat(a: list<string>, b: list<string>) -> list<string>concat(a: list<tile>, b: list<tile>) -> list<tile>concat(a: list<bag>, b: list<bag>) -> list<bag>
A new list with the second joined onto the end of the first.
| Parameter | Type | What it does |
| arequired |
list<int> |
the first list |
| brequired |
list<int> |
the list to add after it |
Example
print("joined", count(concat(range(0, 5), range(0, 5))))
print("joined", count(concat(menuOptions(), menuOptions())))
print("joined", count(concat(path(myTile()), path(myTile()))))
print("joined", count(concat(bagList(), bagList())))
contains
returns bool
contains(items: list<int>, value: int) -> boolcontains(items: list<string>, value: string) -> bool
True when the list holds an item equal to the value. Distinct from contains(text, part), which searches a string.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to search |
| valuerequired |
int |
the item to look for |
Example
if contains(range(0, 5), 9) { stop }
if contains(menuOptions(), "x") { stop }
countOf
returns int
countOf(items: list<int>, value: int) -> intcountOf(items: list<string>, value: string) -> int
How many times a value appears in a list.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to search |
| valuerequired |
int |
the item to count |
Example
print("twos", countOf(range(0, 5), 9))
print("twos", countOf(menuOptions(), "x"))
countOver
returns int
countOver(items: list<int>, threshold: int) -> int
How many numbers in the list are STRICTLY over a threshold — one call instead of a counting loop.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to tally |
| thresholdrequired |
int |
the number to measure against |
Example
print(countOver(range(0, 10), 5))
countUnder
returns int
countUnder(items: list<int>, threshold: int) -> int
How many numbers in the list are STRICTLY under a threshold — the other side of countOver.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to tally |
| thresholdrequired |
int |
the number to measure against |
Example
print(countUnder(range(0, 10), 5))
deltas
returns list<int>
deltas(items: list<int>) -> list<int>
Each gap between neighbours: 3, 5, 9 becomes 2, 4 — one shorter than the input, and empty for a list of one or none.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to difference |
Example
print(count(deltas(range(0, 5))))
difference
returns list<int>
difference(a: list<int>, b: list<int>) -> list<int>
A new list of the numbers in the first list that are not in the second, without duplicates.
| Parameter | Type | What it does |
| arequired |
list<int> |
the list to keep from |
| brequired |
list<int> |
the list of numbers to drop |
Example
print("only in a", count(difference(range(0, 5), range(3, 8))))
distinct
returns list<int> or list<string>
distinct(items: list<int>) -> list<int>distinct(items: list<string>) -> list<string>
A new list with duplicates removed, keeping the first of each in order. Numbers and text only, since those compare by value.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to dedupe |
Example
print("unique", count(distinct(range(0, 5))))
print("unique", count(distinct(menuOptions())))
first
returns int? or string? or tile? or bag?
first(items: list<int>) -> int?first(items: list<string>) -> string?first(items: list<tile>) -> tile?first(items: list<bag>) -> bag?
The first item in a list, or none when the list is empty. Test the none the way you test items[0].
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to read the front of |
Example
if first(range(0, 5)) == none { stop }
if first(menuOptions()) == none { stop }
if first(path(myTile())) == none { stop }
if first(bagList()) == none { stop }
indexOf
returns int
indexOf(items: list<int>, value: int) -> intindexOf(items: list<string>, value: string) -> int
Where the value first sits in the list, counting from zero, or -1 when it is not there — the same convention as dialogueIndexOf.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to search |
| valuerequired |
int |
the item to find the position of |
Example
print("at", indexOf(range(0, 5), 9))
print("at", indexOf(menuOptions(), "x"))
indexOfFrom
returns int?
indexOfFrom(items: list<int>, value: int, from: int) -> int?indexOfFrom(items: list<string>, value: string, from: int) -> int?
Where a value appears at or after a position, or none when it does not — indexOf, resumed part way through the list.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to search |
| valuerequired |
int |
the value to look for |
| fromrequired |
int |
the position to start looking at, counting from 0 |
Example
print(indexOfFrom(range(0, 5), 9, 1))
print(indexOfFrom(menuOptions(), "x", 1))
indexOfMax
returns int?
indexOfMax(items: list<int>) -> int?
Where the largest number sits, counting from 0 — ties answer the earliest. None for an empty list. Pair it with removeAt or replaceAt.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to scan |
Example
print(indexOfMax(range(0, 5)))
indexOfMin
returns int?
indexOfMin(items: list<int>) -> int?
Where the smallest number sits, counting from 0 — ties answer the earliest. None for an empty list.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to scan |
Example
print(indexOfMin(range(0, 5)))
insert
returns list<int> or list<string> or list<tile> or list<bag>
insert(items: list<int>, index: int, value: int) -> list<int>insert(items: list<string>, index: int, value: string) -> list<string>insert(items: list<tile>, index: int, value: tile) -> list<tile>insert(items: list<bag>, index: int, value: bag) -> list<bag>
A new list with the value inserted at a position, sliding the rest along. The index is clamped, so it goes on the end when it is past it.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to add into |
| indexrequired |
int |
where to put it, counting from zero |
| valuerequired |
int |
the item to insert |
Example
print("longer", count(insert(range(0, 5), 1, 9)))
print("longer", count(insert(menuOptions(), 1, "x")))
print("longer", count(insert(path(myTile()), 1, myTile())))
print("longer", count(insert(bagList(), 1, newBag())))
interleave
returns list<int> or list<string>
interleave(a: list<int>, b: list<int>) -> list<int>interleave(a: list<string>, b: list<string>) -> list<string>
The two lists woven together one from each in turn; whichever runs out first, the rest of the other follows. Capped like every list.
| Parameter | Type | What it does |
| arequired |
list<int> |
the list whose items go first |
| brequired |
list<int> |
the list whose items alternate in |
Example
print(count(interleave(range(0, 3), range(0, 3))))
print(count(interleave(menuOptions(), menuOptions())))
intersection
returns list<int>
intersection(a: list<int>, b: list<int>) -> list<int>
A new list of the numbers in both lists, without duplicates.
| Parameter | Type | What it does |
| arequired |
list<int> |
the first list |
| brequired |
list<int> |
the second list |
Example
print("both", count(intersection(range(0, 5), range(3, 8))))
isSorted
returns bool
isSorted(items: list<int>) -> bool
True when the numbers never go down along the list — equal neighbours count as sorted. Empty and single lists are sorted.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to check |
Example
if isSorted(range(0, 5)) { print("ordered") }
join
returns string
join(texts: list<string>, separator: string) -> string
The strings run together with the separator between each — the inverse of split.
| Parameter | Type | What it does |
| textsrequired |
list<string> |
the strings to join |
| separatorrequired |
string |
what to put between them |
Example
print(join(menuOptions(), ", "))
joinNumbers
returns string
joinNumbers(numbers: list<int>, separator: string) -> string
The numbers run together as text with the separator between each.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to join |
| separatorrequired |
string |
what to put between them |
Example
print(joinNumbers(range(0, 3), ", "))
last
returns int? or string? or tile? or bag?
last(items: list<int>) -> int?last(items: list<string>) -> string?last(items: list<tile>) -> tile?last(items: list<bag>) -> bag?
The last item in a list, or none when the list is empty.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to read the end of |
Example
if last(range(0, 5)) == none { stop }
if last(menuOptions()) == none { stop }
if last(path(myTile())) == none { stop }
if last(bagList()) == none { stop }
lastIndexOf
returns int?
lastIndexOf(items: list<int>, value: int) -> int?lastIndexOf(items: list<string>, value: string) -> int?
Where a value LAST appears in a list, or none when it never does — the other end of indexOf.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to search |
| valuerequired |
int |
the value to look for |
Example
print(lastIndexOf(range(0, 5), 9))
print(lastIndexOf(menuOptions(), "x"))
maxOf
returns int?
maxOf(numbers: list<int>) -> int?
The largest number in the list, or none when the list is empty.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to search |
Example
if maxOf(range(0, 5)) == none { stop }
maxText
returns string?
maxText(texts: list<string>) -> string?
The alphabetically last string in the list, or none when it is empty.
| Parameter | Type | What it does |
| textsrequired |
list<string> |
the strings to compare |
Example
if maxText(menuOptions()) == none { stop }
mean
returns int?
mean(numbers: list<int>) -> int?
The average of the numbers, rounded down, or none when the list is empty.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to average |
Example
if mean(range(0, 5)) == none { stop }
median
returns int?
median(numbers: list<int>) -> int?
The middle number once the list is sorted, or the lower of the two middles for an even count. None when the list is empty.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to find the middle of |
Example
if median(range(0, 5)) == none { stop }
minOf
returns int?
minOf(numbers: list<int>) -> int?
The smallest number in the list, or none when the list is empty.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to search |
Example
if minOf(range(0, 5)) == none { stop }
minText
returns string?
minText(texts: list<string>) -> string?
The alphabetically first string in the list, or none when it is empty.
| Parameter | Type | What it does |
| textsrequired |
list<string> |
the strings to compare |
Example
if minText(menuOptions()) == none { stop }
modeOf
returns int?
modeOf(items: list<int>) -> int?
The most common number in a list — a tie answers the one seen first. None when the list is empty.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to tally |
Example
print(modeOf(range(0, 5)))
numbersIn
returns list<int>
numbersIn(text: string) -> list<int>
Every run of digits in a line as numbers, commas ignored. 'traded 1,000 for 250' reads as 1000 and 250. Empty when the line holds no number.
| Parameter | Type | What it does |
| textrequired |
string |
the text to scan |
Example
print("nums", count(numbersIn("traded 1,000 for 250")))
numbersToTexts
returns list<string>
numbersToTexts(numbers: list<int>) -> list<string>
A new list of the numbers written as strings, for joining or comparing as text.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to convert |
Example
print("as text", count(numbersToTexts(range(0, 3))))
offsetAll
returns list<int>
offsetAll(items: list<int>, by: int) -> list<int>
Every number in a list with the same amount added — sliding a whole series. Faults if any sum overflows.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to shift |
| byrequired |
int |
what to add to every one (negative subtracts) |
Example
print(first(offsetAll(range(0, 3), 100)))
padList
returns list<int> or list<string>
padList(items: list<int>, value: int, size: int) -> list<int>padList(items: list<string>, value: string, size: int) -> list<string>
The list lengthened to a size by appending copies of a value — a list already long enough comes back unchanged. Capped like every list.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to lengthen |
| valuerequired |
int |
what to append until the size is reached |
| sizerequired |
int |
how long the answer should be |
Example
print(count(padList(range(0, 3), 0, 8)))
print(count(padList(menuOptions(), "-", 8)))
pairDiffs
returns list<int>
pairDiffs(a: list<int>, b: list<int>) -> list<int>
The two lists combined position by position, each pair subtracted, first minus second. Refuses lists of different sizes and faults if a result overflows.
| Parameter | Type | What it does |
| arequired |
list<int> |
the first list of numbers |
| brequired |
list<int> |
the second, the same size as the first |
Example
print(first(pairDiffs(range(10, 13), range(0, 3))))
pairProducts
returns list<int>
pairProducts(a: list<int>, b: list<int>) -> list<int>
The two lists combined position by position, each pair multiplied together. Refuses lists of different sizes and faults if a result overflows.
| Parameter | Type | What it does |
| arequired |
list<int> |
the first list of numbers |
| brequired |
list<int> |
the second, the same size as the first |
Example
print(first(pairProducts(range(1, 4), range(1, 4))))
pairSums
returns list<int>
pairSums(a: list<int>, b: list<int>) -> list<int>
The two lists combined position by position, each pair added together. Refuses lists of different sizes and faults if a result overflows.
| Parameter | Type | What it does |
| arequired |
list<int> |
the first list of numbers |
| brequired |
list<int> |
the second, the same size as the first |
Example
print(first(pairSums(range(0, 3), range(10, 13))))
product
returns int
product(numbers: list<int>) -> int
Every number in the list multiplied together — one for an empty list. Faults if the result is too big to hold.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to multiply |
Example
print("factorial-ish", product(range(1, 6)))
randomFrom
returns int?
randomFrom(numbers: list<int>) -> int?
A number picked at random from the list, or none when the list is empty.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to pick from |
Example
if randomFrom(range(0, 5)) == none { stop }
randomText
returns string?
randomText(texts: list<string>) -> string?
A string picked at random from the list, or none when the list is empty.
| Parameter | Type | What it does |
| textsrequired |
list<string> |
the strings to pick from |
Example
if randomText(menuOptions()) == none { stop }
range
returns list<int>
range(from: int, toExclusive: int) -> list<int>
The numbers from 'from' up to but not including 'toExclusive'. range(0, 3) is 0, 1, 2. The list to walk with 'for' when you want a count rather than a query.
| Parameter | Type | What it does |
| fromrequired |
int |
the first number, included |
| toExclusiverequired |
int |
one past the last number |
Example
print("count", count(range(0, 10)))
rangeStep
returns list<int>
rangeStep(from: int, toExclusive: int, step: int) -> list<int>
Like range, but counting by 'step': rangeStep(0, 10, 2) is 0, 2, 4, 6, 8. Refuses a zero step.
| Parameter | Type | What it does |
| fromrequired |
int |
the first number, included |
| toExclusiverequired |
int |
one past the last number |
| steprequired |
int |
how far apart the numbers are; must not be zero |
Example
print("tens", count(rangeStep(0, 100, 10)))
removeAt
returns list<int> or list<string> or list<tile> or list<bag>
removeAt(items: list<int>, index: int) -> list<int>removeAt(items: list<string>, index: int) -> list<string>removeAt(items: list<tile>, index: int) -> list<tile>removeAt(items: list<bag>, index: int) -> list<bag>
A new list with the item at a position removed. An index off the end leaves the list unchanged.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to remove from |
| indexrequired |
int |
which item to drop, counting from zero |
Example
print("shorter", count(removeAt(range(0, 5), 0)))
print("shorter", count(removeAt(menuOptions(), 0)))
print("shorter", count(removeAt(path(myTile()), 0)))
print("shorter", count(removeAt(bagList(), 0)))
removeEvery
returns list<int> or list<string>
removeEvery(items: list<int>, value: int) -> list<int>removeEvery(items: list<string>, value: string) -> list<string>
The list with EVERY appearance of a value removed, the input unchanged — removeValue for all of them at once.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to work on |
| valuerequired |
int |
the value to remove wherever it appears |
Example
print(count(removeEvery(range(0, 5), 9)))
print(count(removeEvery(menuOptions(), "x")))
removeValue
returns list<int> or list<string>
removeValue(items: list<int>, value: int) -> list<int>removeValue(items: list<string>, value: string) -> list<string>
The list with the FIRST appearance of a value removed, the input unchanged. A value not there leaves the list as it was.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to work on |
| valuerequired |
int |
the value to remove once |
Example
print(count(removeValue(range(0, 5), 9)))
print(count(removeValue(menuOptions(), "x")))
repeated
returns list<int>
repeated(value: int, times: int) -> list<int>
A list holding the same number a number of times — a seed to fill in, or a fixed run of a value.
| Parameter | Type | What it does |
| valuerequired |
int |
the number to repeat |
| timesrequired |
int |
how many copies, zero or more |
Example
print("fives", count(repeated(5, 4)))
replaceAt
returns list<int> or list<string> or list<tile> or list<bag>
replaceAt(items: list<int>, index: int, value: int) -> list<int>replaceAt(items: list<string>, index: int, value: string) -> list<string>replaceAt(items: list<tile>, index: int, value: tile) -> list<tile>replaceAt(items: list<bag>, index: int, value: bag) -> list<bag>
A new list with the item at a position replaced. An index off the end leaves the list unchanged.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to change |
| indexrequired |
int |
which item to replace, counting from zero |
| valuerequired |
int |
what to put there |
Example
print("same count", count(replaceAt(range(0, 5), 0, 9)))
print("same count", count(replaceAt(menuOptions(), 0, "x")))
print("same count", count(replaceAt(path(myTile()), 0, myTile())))
print("same count", count(replaceAt(bagList(), 0, newBag())))
reversed
returns list<int> or list<string> or list<tile> or list<bag>
reversed(items: list<int>) -> list<int>reversed(items: list<string>) -> list<string>reversed(items: list<tile>) -> list<tile>reversed(items: list<bag>) -> list<bag>
A new list with the items in the opposite order.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to turn around |
Example
print("same count", count(reversed(range(0, 5))))
print("same count", count(reversed(menuOptions())))
print("same count", count(reversed(path(myTile()))))
print("same count", count(reversed(bagList())))
rotate
returns list<int> or list<string> or list<tile> or list<bag>
rotate(items: list<int>, by: int) -> list<int>rotate(items: list<string>, by: int) -> list<string>rotate(items: list<tile>, by: int) -> list<tile>rotate(items: list<bag>, by: int) -> list<bag>
A new list rotated round by a number of places, so the front wraps to the back. Negative rotates the other way.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to rotate |
| byrequired |
int |
how many places to move the front to the back |
Example
print("same count", count(rotate(range(0, 5), 1)))
print("same count", count(rotate(menuOptions(), 1)))
print("same count", count(rotate(path(myTile()), 1)))
print("same count", count(rotate(bagList(), 1)))
runningTotals
returns list<int>
runningTotals(items: list<int>) -> list<int>
Each position replaced by the total so far: 1, 2, 3 becomes 1, 3, 6 — the shape a growing graph wants. Faults if a total overflows.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to total |
Example
print(last(runningTotals(range(1, 4))))
sample
returns list<int> or list<string>
sample(items: list<int>, howMany: int) -> list<int>sample(items: list<string>, howMany: int) -> list<string>
Some of the list at random, no position taken twice, in shuffled order — a hand of cards from a deck. Asking for more than there is answers all of it, shuffled.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to draw from |
| howManyrequired |
int |
how many to take, 0 or more |
Example
print(count(sample(range(0, 10), 2)))
print(count(sample(menuOptions(), 2)))
scaleAll
returns list<int>
scaleAll(items: list<int>, by: int) -> list<int>
Every number in a list multiplied by the same amount — scaling a whole series. Faults if any product overflows.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to scale |
| byrequired |
int |
what to multiply every one by |
Example
print(first(scaleAll(range(1, 4), 10)))
shuffle
returns list<int>
shuffle(numbers: list<int>) -> list<int>
A new list of the numbers in a random order — for visiting spots in a different order each run.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to shuffle |
Example
print("same count", count(shuffle(range(0, 5))))
skip
returns list<int> or list<string> or list<tile> or list<bag>
skip(items: list<int>, howMany: int) -> list<int>skip(items: list<string>, howMany: int) -> list<string>skip(items: list<tile>, howMany: int) -> list<tile>skip(items: list<bag>, howMany: int) -> list<bag>
A new list with the first few items dropped — the tail of a list. The pair to take, and how you trim a rolling window: xs = skip(xs, count(xs) - 10).
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to skip in |
| howManyrequired |
int |
how many from the front to drop |
Example
print("tail", count(skip(range(0, 5), 2)))
print("tail", count(skip(menuOptions(), 2)))
print("tail", count(skip(path(myTile()), 2)))
print("tail", count(skip(bagList(), 2)))
slice
returns list<int> or list<string> or list<tile> or list<bag>
slice(items: list<int>, from: int, toExclusive: int) -> list<int>slice(items: list<string>, from: int, toExclusive: int) -> list<string>slice(items: list<tile>, from: int, toExclusive: int) -> list<tile>slice(items: list<bag>, from: int, toExclusive: int) -> list<bag>
A new list of the items between two positions. Both ends are clamped to the list, so an over-long range never faults.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to cut from |
| fromrequired |
int |
the first item to keep, counting from zero |
| toExclusiverequired |
int |
one past the last item to keep |
Example
print("middle", count(slice(range(0, 5), 1, 3)))
print("middle", count(slice(menuOptions(), 1, 3)))
print("middle", count(slice(path(myTile()), 1, 3)))
print("middle", count(slice(bagList(), 1, 3)))
sorted
returns list<int> or list<string>
sorted(numbers: list<int>) -> list<int>sorted(texts: list<string>) -> list<string>
A new list of the numbers in ascending order.
A new list of the strings in order, case by byte value.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to sort |
| textsrequired |
list<string> |
the strings to sort |
Example
print("sorted", count(sorted(range(0, 5))))
print("sorted", count(sorted(menuOptions())))
sortedDesc
returns list<int>
sortedDesc(numbers: list<int>) -> list<int>
A new list of the numbers in descending order — largest first.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to sort |
Example
print("top", count(sortedDesc(range(0, 5))))
sortedTexts
returns list<string>
sortedTexts(items: list<string>) -> list<string>
The texts in alphabetical order, case-sensitive, the input unchanged — the text partner of sorted().
| Parameter | Type | What it does |
| itemsrequired |
list<string> |
the texts to sort |
Example
print(first(sortedTexts(menuOptions())))
sortedTextsDesc
returns list<string>
sortedTextsDesc(items: list<string>) -> list<string>
The texts in reverse alphabetical order, the input unchanged — sortedTexts, backwards.
| Parameter | Type | What it does |
| itemsrequired |
list<string> |
the texts to sort |
Example
print(first(sortedTextsDesc(menuOptions())))
spanOf
returns int?
spanOf(items: list<int>) -> int?
The distance from the smallest number in a list to the largest — max minus min. None when the list is empty.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the numbers to measure |
Example
print(spanOf(range(3, 9)))
split
returns list<string>
split(text: string, separator: string) -> list<string>
The text cut into pieces wherever 'separator' appears — the other half of the string helpers. Refuses an empty separator, which would have no pieces.
| Parameter | Type | What it does |
| textrequired |
string |
the text to cut up |
| separatorrequired |
string |
the exact fragment to cut on; must not be empty |
Example
print("parts", count(split("a,b,c", ",")))
sum
returns int
sum(numbers: list<int>) -> int
Every number in the list added together. Faults if the total is too big to hold, like the + operator does.
| Parameter | Type | What it does |
| numbersrequired |
list<int> |
the numbers to add up |
Example
print("total", sum(range(0, 5)))
swap
returns list<int> or list<string> or list<tile> or list<bag>
swap(items: list<int>, first: int, second: int) -> list<int>swap(items: list<string>, first: int, second: int) -> list<string>swap(items: list<tile>, first: int, second: int) -> list<tile>swap(items: list<bag>, first: int, second: int) -> list<bag>
A new list with two items exchanged. Either index off the end leaves the list unchanged.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to reorder |
| firstrequired |
int |
one position, counting from zero |
| secondrequired |
int |
the other position |
Example
print("same count", count(swap(range(0, 5), 0, 1)))
print("same count", count(swap(menuOptions(), 0, 1)))
print("same count", count(swap(path(myTile()), 0, 1)))
print("same count", count(swap(bagList(), 0, 1)))
take
returns list<int> or list<string> or list<tile> or list<bag>
take(items: list<int>, howMany: int) -> list<int>take(items: list<string>, howMany: int) -> list<string>take(items: list<tile>, howMany: int) -> list<tile>take(items: list<bag>, howMany: int) -> list<bag>
A new list of the first few items. Asking for more than there are just gives all of them.
| Parameter | Type | What it does |
| itemsrequired |
list<int> |
the list to take from |
| howManyrequired |
int |
how many from the front |
Example
print("first two", count(take(range(0, 5), 2)))
print("first two", count(take(menuOptions(), 2)))
print("first two", count(take(path(myTile()), 2)))
print("first two", count(take(bagList(), 2)))
union
returns list<int>
union(a: list<int>, b: list<int>) -> list<int>
A new list of the numbers in either list, without duplicates, in first-seen order.
| Parameter | Type | What it does |
| arequired |
list<int> |
the first list |
| brequired |
list<int> |
the second list |
Example
print("either", count(union(range(0, 3), range(2, 5))))
No command on this page matches that. The search box looks across every page.