ComfyUI Node

List Ops

Sort, shuffle, dedupe, and join the lists your text nodes spit out

By wwsmiao·Created 4 months ago·Updated 4 months ago· 0
List Ops
    • result
    items
    operationjoin
    param,
    seed0

    TextSplit, TxtReg, and TextFilterLines all hand you lists. ListOps is what happens to them next. It takes a string list in, applies one of ten operations, and hands a list back out - the "post-processing" step of the wwdm-aicd pack's data pipeline, and honestly the node that ties the whole thing together.

    Everything hangs off the operation dropdown. join is the one most people land on first: it flattens the list into a single string using param as the separator, so ["a","b","c"] with param: ", " becomes "a, b, c". sort and sort_desc do alphabetical order, reverse flips it, dedupe removes duplicates while keeping first-seen order, and sort_by_length sorts by string length instead of alphabetically. take and skip use param as a number - first N items, or drop the first N. chunk groups by size. Then there's shuffle, which randomly reorders and is the only one that cares about seed: set a non-zero seed and the shuffle is reproducible, leave it at 0 and it uses Python's global random.

    Two mechanism details are worth knowing, because both are the kind of thing you'd call a bug until you check the source. First, chunk doesn't return nested lists - it extends the result flat, so ["a","b","c","d"] chunked by 2 comes back as ["a","b","c","d"], unchanged in shape. If you were hoping for [["a","b"],["c","d"]] for a downstream node that expects grouped data, this isn't it. Second, join returns a single string wrapped in a list, so the output is always list-typed no matter what operation you run - you don't get a bare STRING socket. That's consistent, and it means whatever consumes the output has to handle a list.

    The inputs: items is the list (it expects a list socket, so feed it TxtReg/TextSplit/JsonParser output, not a raw string), operation is the choice, param is the overloaded one (separator for join, count for chunk/take/skip - and for chunk and take it parses param as an int, defaulting to 2 and 1 respectively if the parse fails), and seed for shuffle. Output is one STRING list called result.

    Install is the pack's usual easy story:

    cd ComfyUI/custom_nodes
    git clone https://github.com/wwsmiao/comfyui-wwdm-aicd.git
    

    Restart ComfyUI, find it under wwdm-aicd. Pure stdlib, no models, no requirements.txt in the repo despite what the README's install section implies - skip that step. README and code comments are in Chinese; widget labels are English.

    Where it shines: after TxtReg extracts a pile of matches, sort + dedupe to clean it up, then join to turn it into a comma string for a prompt; or shuffle with a fixed seed to randomize prompt variants reproducibly. And if you need to shuffle with fresh results every run, remember the seed-0 path rides on ComfyUI's cache - set a real seed or drive it from a changing input, or the "random" can feel sticky. It's small, it's boring, and it's the node that makes the list-producing ones actually useful.

    Categorywwdm-aicd

    Inputs (4)

    NameTypeDefaultDescription
    itemsSTRING
    operationCOMBOjoin10 options: join, sort, sort_desc, reverse, dedupe, shuffle, +4
    paramoptSTRING,
    seedoptINT00–999999

    Outputs (1)

    NameTypeDescription
    resultSTRING