You can write a generator function that takes a sequence and gives every possible combination of negatives. Like this:
import itertools def negations(seq): for prefixes in itertools.product(["", "-"], repeat=len(seq)): yield [prefix + value for prefix, value in zip(prefixes, seq)] print list(negations(["a", "b", "c"]))
Result (spaces modified for clarity):
[ [ 'a', 'b', 'c'], [ 'a', 'b', '-c'], [ 'a', '-b', 'c'], [ 'a', '-b', '-c'], ['-a', 'b', 'c'], ['-a', 'b', '-c'], ['-a', '-b', 'c'], ['-a', '-b', '-c'] ]
You can integrate this into your existing code with something like
comb = [x for i in range(1, len(data)+1) for c in combinations(data, i) for x in negations(c)]