I have an input list L containing about 20-30 elements. I need to keep some of the subsets of L, that satisfy a given condition, so that I can iterate over them later. I can create the list of subsets in the following way:
good_subsets = list([s for s in powerset(L) if condition(s)])
This works, but might consume a lot of memory. For example, if L has 20 elements, and 50% of them satisfy the condition, then there are about 500,000 subsets.
Is there a more compact way to store the good_subsets in a list? Note that it should be a list and not a generator, since I need to iterate over this list many times later on, and I do not want to generate it each time anew.