Nodes/ComfyUI-list-filter/Filter String List
ComfyUI Node

Filter String List

Pull the strings you actually care about out of a batch

By Kesin11·Created 2 years ago·Updated about a year ago· 1
Filter String List
    • filtered_list
    string_list
    index_list0

    Filter String List is the string-flavored cousin of Filter Image List from the same pack, and it solves the same class of problem: you've got a batch of things, you've got a list of indices, and you only want the entries at those positions. Here the "things" are strings - usually tag lines, prompts, or filenames.

    The use case that made the pack's author build it: ComfyUI-WD14-Tagger tags every image in a batch, giving you one string per image. That list of tag lines is useful in aggregate, but what you often want is the subset that matches something. Pair this node with Find Any Strings and you can grab exactly the tag lines that mention a given tag, or hand the matching indices to Filter Image List to pull the actual images. It's the plumbing between "I have a list" and "I have the right ones."

    How it works

    It's a list comprehension with a guard: keep string_list[i] for every i in index_list where i < len(string_list). Two things fall out of that.

    First, out-of-range indices are silently dropped rather than raising an error. Pass [0, 5, 99] against a three-element list and you get two results, no complaint, no red node. Convenient, but it also means a bad index won't announce itself.

    Second, the order of the output follows your index_list, not the original order - and duplicates are preserved. [2, 0, 2] gives you the third, first, then third entry again. That's usually exactly what you want when the index list came from a selection UI.

    The inputs that matter

    • string_list - the list of strings to filter. Because the node runs with INPUT_IS_LIST, this arrives as a real list from whichever node feeds it (Tagger output, ShowText, a prompt combinator).
    • index_list - the INT indices to keep. Feed it directly from Index List From String (list_filter_StringToIndex) if your indices start life as text.

    The single output, filtered_list, is a STRING list. Wire it into a ShowText node to eyeball what survived, or keep it in the string side of your graph for the next step.

    Installing it

    Same routine as the whole pack - this is one of six nodes in ComfyUI-list-filter, and it installs with all of them:

    • ComfyUI Manager - search ComfyUI-list-filter and install, then restart.
    • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/Kesin11/ComfyUI-list-filter, then restart.

    No requirements.txt, no models, no GPU-side deps. The pack imports nothing but random under the hood, so this node can't drag dependency conflicts into your environment - a small mercy in the custom node world, where most installs come with a laundry list of pip packages.

    Gotchas worth knowing

    • Silent drops: indices past the end of the list just vanish. If a filter comes back shorter than you expect, check the indices, not the node.
    • Zero-based, always. 0 is the first item.
    • It filters by position, not by content. If you want "strings that contain X", you want Find Any Strings or Find Not Any Strings, which produce the index list for this node.

    It's a boring node in the best way. You'll reach for it constantly once you're working with tag lists and prompt batches, and it'll never be the thing that breaks.

    Categorylist-filter

    Inputs (2)

    NameTypeDefaultDescription
    string_listSTRINGThe list of strings to be filtered.
    index_listINT0The list of indices to filter the string list.

    Outputs (1)

    NameTypeDescription
    filtered_listSTRINGThe filtered list of strings.