Truncate a list

Truncate a list by keeping N items. Default Pick mode is First (the first N items in order). Switch to Random (random sample without replacement), Longest (N longest by character count), or Shortest (N shortest). Default N is 5. Same op as Head of a list.

Input
Ready
Output
Live

Four pick modes, one N parameter

First (default): keeps items 0..N-1 in their original order. Random: Fisher-Yates shuffle then take first N - unseeded, so each run produces a different sample unless you copy the output. Longest / Shortest: sorts by `line.length` then takes N from the top.

If N is larger than the list, the entire list is emitted - there is no padding or error. N ≤ 0 produces an empty output.

Same op as Head of a list. The inverse framing (`keep the LAST N`) is Tail of a list, which shares the mode set.

How to use truncate a list

  1. 1Paste your list into the input panel
  2. 2Set Keep N (default 5)
  3. 3Pick mode: First (default), Random, Longest, or Shortest
  4. 4Output contains at most N items
  5. 5For the LAST N instead, use Tail of a list

Keyboard shortcuts

Drive ListShift without touching the mouse.

Shortcut Action
Ctrl ZUndo last input change
Ctrl Shift ZRedo
Ctrl Shift EnterToggle fullscreen focus on the editor
EscExit fullscreen
Ctrl KOpen the command palette to jump to any tool
Ctrl SSave current pipeline draft Plus
Ctrl PRun a saved pipeline Plus

What this tool actually does

Bounded keep-N with four selection strategies.

First: order-preserving head slice

Takes items 0..N-1 in input order. Deterministic and fast.

Random: unseeded Fisher-Yates sample

Shuffles the list then takes the first N. No seed input - repeat runs yield different samples. Copy the output if you need it reproducibly.

Longest: N longest by character count

Sorts by line length descending, takes first N. Ties resolved by original order (stable sort). Useful for finding verbose items or longest URLs.

Shortest: N shortest by character count

Opposite of Longest. Handy for finding terse items or suspicious outliers (1-character entries, typos).

No padding if list is shorter than N

Output is `min(N, list.length)` items. An empty list stays empty. N ≤ 0 produces empty output.

Worked example

Default N=5, Pick=First. Keeps `apple` through `elderberry`, drops `fig` and `grape`.

Input
apple
banana
cherry
date
elderberry
fig
grape
Output
apple
banana
cherry
date
elderberry

Settings reference

How each option shapes the output using the sample above (7 items).

Setting What it does Effect on the sample
Keep N: 5 (default), Pick: First (default) First 5 items in order `apple` / `banana` / `cherry` / `date` / `elderberry`
Pick: Random 5 random items, different each run Sample varies - e.g. `date, fig, apple, cherry, grape`
Pick: Longest 5 longest by character length `elderberry` (10), `banana` (6), `cherry` (6), `grape` (5), `apple` (5)
Pick: Shortest 5 shortest by character length `fig` (3), `date` (4), `apple` (5), `grape` (5), `cherry` (6)
Keep N: 100 (bigger than list) Entire list emitted All 7 items, no padding

FAQ

What does Pick = Random do exactly?
Performs a Fisher-Yates shuffle on the full list then takes the first N items. Unseeded `Math.random()`, so each run produces a different sample.
How does Longest / Shortest break ties?
Ties preserve original input order (stable sort). So among items all of length 6, the first one in input appears first in output.
What if N is larger than the list?
The entire list is emitted. No error, no padding. Shorter lists just yield fewer output lines.
How is this different from Head of a list?
Same op. Head of a list is the alternative URL with the same four modes.
How do I keep the LAST N items instead?
Use Tail of a list - same op family but the default mode is Last (inverse of First).