ComfyUI Node

sort

Sort your list — and don't trip over the silent failure

By StableLlama·Created about a year ago·Updated 4 days ago· 48
sort
  • list
  • LIST
reverseFalse

Order in the court

Sort is one of those list operations you'll reach for constantly once you're building data-pipeline workflows: sort your prompts alphabetically, sort seeds low-to-high, sort a list of filenames before feeding them somewhere order-sensitive. This node takes a LIST and returns a new, sorted LIST, with a toggle for ascending or descending.

It's plain Python's sorted() exposed as a node, and because it returns a new list, your original stays exactly as it was. That's the behavior you want in a graph where the same LIST might feed several branches.

How it works

The node runs sorted(list, reverse=...) on a copy. Numeric lists sort numerically, string lists sort alphabetically (by code point, so "Z" sorts before "a" - a classic gotcha if you have mixed-case text). The reverse option is a dropdown - False (default) ascending, True descending - so you never need to chain a reverse node afterward.

Here's the part worth knowing before you hit it: if the list contains items that can't be compared to each other (an int next to a string, say), sorted() throws a TypeError - and this node catches it and returns the original list unchanged, silently. No error box, no warning. That's friendly in the sense that your graph won't crash, but it also means a mixed-type list gives you back an unsorted list and you might not realize why. If a sort looks like it did nothing, that's your suspect.

Inputs and outputs

  • list (LIST) - the list to sort.
  • reverse (enum, default False) - set to True for descending order.

Output is a single LIST: the sorted result.

Installing it

Part of Basic data handling by StableLlama, the r/StableDiffusion regular known for his model deep-dives (his Flux Klein 9B conclusions post was a highlight of that release) more than his code. The pack itself is refreshingly plain: zero runtime dependencies in its pyproject, no model files, no API calls.

Install via ComfyUI Manager (search "Basic data handling") or:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart ComfyUI; it's under Basic/LIST.

Troubleshooting

The silent-failure thing is the big one - if your list comes back unsorted, you've almost certainly got mixed types in it, so inspect what's actually in the LIST. Second: case matters for strings, and "10" as a string sorts before "2" because "1" < "2" - if your numbers are strings, cast them with the pack's casting nodes first. And this is LIST-only; a native ComfyUI data list won't connect to the input.

CategoryBasic/LIST

Inputs (2)

NameTypeDefaultDescription
listLIST
reverseoptCOMBOFalse2 options: False, True

Outputs (1)

NameTypeDescription
LISTLIST