itertools
itertools copied to clipboard
prunable combinations iterator
This might be specific enough that i need to roll my own solution, but here goes.
I have a set of objects from which i need to iterate over all possible combinations. The combinations iterator is perfect, except...
- the number of possible combinations is very large
- not all combinations are 'valid'
- I can usually tell if a particular combination is not 'valid' by looking at a subset of the combination's elements
basically i want to be able to use a predicate to prune combinations early. If I add the pruning step after the combinations function then it is prohibitively expensive to count the combinations, even if the total number of valid combinations is very small
You might have to roll your own solution (if you did not already did) but as I know the internal well enough after contributing to it, maybe this is simple/general enough.
First, what do you mean by early? Just to avoid to allocate each item to a vector but still going through them one by one? Or early knowing the X next items would be wrong? Something else?
There is tuple_combinations too, which has really different internals.