I have a list of elements of a custom class Fun. What I want is to generate all possible summations of this list. For example, if I have the list [Fun1, Fun2, Fun3], I want to generate the list:
[[Fun1 + Fun2, Fun3], [Fun1 + Fun3, Fun2], [Fun2 + Fun3, Fun1], [Fun1, Fun2, Fun3], [Fun1 + Fun2 + Fun3]]
This should generate for longer lists but I know that all elements of my list are of the same type, a custom class named Fun. And it is possible to sum elements of the class Fun, I already implemented the way they are supposed to be summed.
I have tried several ways to generate this list of possible summations, mainly using variations of itertools.combinations and itertools.product but without success. I have also tried list comprehension (things like [[x + y for x in my_list if x != y] for y in my_list]
) without success. Usually, I get bugs like "type Fun is not iterable" or my output is only one element (the original one).