ComfyUI Node Runs on cloud

Combinations

Every n-way grouping of a sequence, without writing them out by hand

By ali1234·Created 3 years ago·Updated 3 months ago· 130
Combinations
  • sequence
  • sequence
count0
replacementfalse

Say you've got five LoRAs and you want to test every pair of them stacked together - that's ten pairs, and typing them all into a Literal box by hand is exactly the kind of tedious, error-prone busywork a "for loop" pack exists to remove. Combinations generates every unique n-way grouping of a sequence for you.

How it works

It's a direct wrap of Python's itertools.combinations (or itertools.combinations_with_replacement if you allow repeats), picking count elements at a time out of your input sequence. Order doesn't matter to it - ("a", "b") and ("b", "a") are treated as the same grouping and only one shows up in the output. If you specifically need every ordered arrangement rather than every unordered grouping, that's a different tool (this pack also ships a Permutations node for that, though it's not covered here).

The inputs and outputs that matter

  • sequence (SEQUENCE) - the pool you're picking from.
  • count (INT) - how many elements go into each group.
  • replacement (BOOLEAN, default off) - allow the same element to appear more than once within a single combination.

Output is a single sequence - but note each element of it is a tuple, not a bare value. If your next step needs each combination as a single readable string (for a filename, or a prompt), pipe this into the pack's Join node, which flattens each tuple into a joined string.

How to install it

Via ComfyUI Manager: search comfyui-job-iterator, install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ali1234/comfyui-job-iterator

then restart. No dependencies - pure standard-library Python underneath.

Common issues & troubleshooting

The count explodes faster than expected. Combinations of 10 items taken 3 at a time is already 120 groupings. Feed that straight into CombineJobs with product against another sweep and you can end up queuing thousands of runs from one click. Check the size of what you're generating (count it, or just do the math: n! / (r! × (n-r)!) for no replacement) before wiring it into an expensive downstream job.

Downstream nodes error expecting a plain value, not a tuple. GetAttribute and friends hand back whatever's stored - if you skipped the Join step and tried to use a raw tuple like ("a", "b") as, say, a text prompt directly, you'll get a type error or garbled text. Run it through Join first if you need a flat string.

count set to 0. That's technically valid - it produces exactly one empty combination - but it's rarely what you meant. Double-check you set count to how many items you actually want grouped together, not left at its default.

Categoryali1234/sequence

Inputs (3)

NameTypeDefaultDescription
sequenceSEQUENCE
countINT00–9999999
replacementBOOLEANfalse

Outputs (1)

NameTypeDescription
sequenceSEQUENCE