Nodes/ComfyUI-QING/列表取值丨索引
ComfyUI Node

列表取值丨索引

Pull one item out of a list — with a safety net for bad indexes

By sheengoa·Created about a year ago·Updated 19 days ago· 16
列表取值丨索引
    • item
    • ok
    • actual_index
    • length
    default_value
    items
    index0
    index_mode从0开始
    allow_negativetrue

    ComfyUI is full of nodes that produce lists - batches of images, arrays of strings, split text - and surprisingly few that cleanly pull one item out of a list by index without a fight. ListItemGetter is that node: hand it a list, an index, and a fallback, and it returns the item, plus whether the lookup actually succeeded, plus the real index it used and the list length. The ok flag is the part that makes this a genuinely useful plumbing node rather than a toy.

    It's from ComfyUI-QING (display name "列表取值丨索引"), part of the pack's 25-node data-tools section.

    How it works

    The node's items input is INPUT_IS_LIST, meaning it accepts a genuine list of strings (from a text-splitter, a batch node, or another list-producing node). You also give it:

    • index - which item to grab (default 0, range ±1,000,000).
    • index_mode - 从0开始 (0-based) or 从1开始 (1-based). Set it to match whatever the rest of your graph assumes; the node adjusts internally.
    • allow_negative - whether negative indexes count from the end (Python-style). Default on, so -1 grabs the last item.
    • default_value - the fallback returned when the index is out of range.

    The outputs tell you everything:

    • item - the string at that index, or the fallback if the lookup failed.
    • ok - BOOLEAN, true when the index resolved to a real item. This is the output that lets your graph know the lookup failed instead of silently running on a fallback.
    • actual_index - the resolved index after 0/1-based and negative-index handling (so -1 reports the real position, not -1).
    • length - how many items were in the list.

    That last trio is what separates this from a naive "list[index]" - you get diagnostics, not just a value.

    Where it fits

    Classic pattern: a list of prompt variants or filenames comes out of a splitter or a batch collector, and you want to pick variant #3 to feed one branch while the rest flow elsewhere. Set index_mode to 1-based if you're thinking "third item," 0-based if your index comes from a counter that starts at zero. Wire ok into a condition router (or through the pack's IntToBool-family logic) and you've got a branch that handles "index ran past the end of the list" gracefully instead of crashing or returning garbage.

    The one honest limitation: it works on lists of strings, full stop. If you want item N out of a list of images or latents, this isn't the node - it's the string-tier of the pack's list tooling.

    Installing

    Part of ComfyUI-QING - install the pack, get the node. ComfyUI Manager: search "ComfyUI-QING". Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/GAO-SHIQING/ComfyUI-QING
    cd ComfyUI-QING
    python install_dependencies.py   # or: pip install -r requirements.txt
    

    Restart ComfyUI. Pure pip deps (Pillow, opencv-python, scipy, scikit-image, cairosvg), no models. China mirror: --mirror --auto. Python ≥ 3.9.

    Gotchas

    The trap that catches everyone once: it does not split a string for you. If you feed a single multiline string into items, it's treated as one item with length == 1, not as a list of lines. Split it upstream first (the pack has a TextSplitter for exactly that). Second, an empty list returns your fallback with ok false and length 0 - no crash, which is the point, but it's easy to wire item downstream and forget to check ok, then wonder why you got a blank string. Check ok; that's why it's there.

    CategoryQING/数据工具

    Inputs (5)

    NameTypeDefaultDescription
    default_valueSTRING
    itemsSTRING
    indexINT0-1000000–1000000
    index_modeCOMBO从0开始2 options: 从0开始, 从1开始
    allow_negativeBOOLEANtrue

    Outputs (4)

    NameTypeDescription
    itemSTRING
    okBOOLEAN
    actual_indexINT
    lengthINT