Hello,
I'm new in python. I try to generate combinations of objects and calculate sums to characterize them.
A little confused, so I quickly give an example:
I have 3 objects "A", "B", "C" that I want to combine with each other by 2 for example.
In order to achieve this result
[[['A','B'], ['A','C'], ['B','C']]
Now objects have their characteristics
A= {'ST':5, 'SD':7, 'SA':2}
B= {'ST':1, 'SD':3, 'SA':3}
C= {'ST':2, 'SD':2, 'SA':4}
I would like that in addition to obtaining ['A','B'], I have the sum of characteristics of 'A' and 'B'such that[ST=6,SD=10,SA=5] and this for each of the possible combinations.
The expected result would be:
The combination A, B is ST=6,SD=10,SA=5
The combination A, C is ST=7,SD=9,SA=6
The combination B, C is ST=3,SD=5,SA=7
Thank you in advance
I'm new in python. I try to generate combinations of objects and calculate sums to characterize them.
A little confused, so I quickly give an example:
I have 3 objects "A", "B", "C" that I want to combine with each other by 2 for example.
In order to achieve this result
[[['A','B'], ['A','C'], ['B','C']]
Now objects have their characteristics
A= {'ST':5, 'SD':7, 'SA':2}
B= {'ST':1, 'SD':3, 'SA':3}
C= {'ST':2, 'SD':2, 'SA':4}
I would like that in addition to obtaining ['A','B'], I have the sum of characteristics of 'A' and 'B'such that[ST=6,SD=10,SA=5] and this for each of the possible combinations.
The expected result would be:
The combination A, B is ST=6,SD=10,SA=5
The combination A, C is ST=7,SD=9,SA=6
The combination B, C is ST=3,SD=5,SA=7
def comb(m, lst): if m == 0: return [[]] return [[x] + suffix for i, x in enumerate(lst) for suffix in comb(m - 1, lst[i + 1:])] seq=['A','B','C'] print(comb(2, seq))For the moment I can only do the combination....
Thank you in advance