Lets say i have a data table that looks like this:
base + additive pricing
for each combination of index level1 & 2 – a customer could be allocated a price that see’s them get the value base column + the addition of any combination of the a,b,c,d,e columns… including 0 addition, a max. of 5 additions and no repeated column additions (see example of what i mean by this below)…
i.e. combinations / permutation examples:
Permutation1 = value_base
Permutation2 = value_base + value_add_a + value_add_b
Permutation3 = value_base + value_add_c
Permutation4 = value_base + value_add_c + value_add_d + value_add_e
Permutation5 = value_base + value_add_b + value_add_c + value_add_d
Permutation6 = value_base + value_add_a + value_add_d + value_add_e
Permutation7 = value_base + value_add_b + value_add_d + value_add_e
Permutation8 = value_base + value_add_e
and so on…
This example CANT occur:
Permutation5 = value_base + value_add_c + value_add_c + value_add_e
as _c appears more than once!
What I also don’t want is to have “repeated” combinations – where the addition occurs in the same order:
ie. This:
Permutation4 = value_base + value_add_c + value_add_d + value_add_e
gives me the same result as this:
Permutation4 = value_base + value_add_c + value_add_e + value_add_d
so I DONT want this 🙂
I’m looking to code this up in python
currently stuck and unable to think of a solution that can keep a base constant..
import itertools
a = list(itertools.permutations([2, 3, 4, 5, 6]))
b = [1]
c = [list(permutation) + b for permutation in a]
print(c)
have tried looking at **something ** like this – where b can be held constant, BUT the problem with this solution is that combinations can be repeated and the length of the additions is always 6 – where in my solution the length (number of columns added together) can be 1, 2, 3, 4, 5 or 6 (given all possible combinations – remembering that b must be constant, and b can only be the only column addition outcome that has length 1)
GT1981 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.