I'm a beginning programer looking to make a powerset for a list of numbers of varying size (generally at least 150+). The code I have works for smaller lists of numbers but not when I substitute the [4,5,6] for my larger list.
def powerset(s):
x = len(s)
masks = [1 << i for i in range(x)]
for i in range(1 << x):
yield [ss for mask, ss in zip(masks, s) if i & mask]
print(list(powerset([4, 5, 6])))
#this prints: [[], [4], [5], [4, 5], [6], [4, 6], [5, 6], [4, 5, 6]]
(This is not a homework question it is part of a larger code I am writing) Any help is super appreciated and please keep in mind that I have only been programming for a few months. Thank you!
Edit!: I realize now (thank you comments) that this would produce a ridiculously large list, New question: Is there a way to sort the powerset before it is generated. As in, instead of getting rid of any sets it produces with less than a certain number of numbers after the generator runs, is there a way to make it so the generator does not produce lists with certain characteristics (size, specific number, etc.) This way it would produce a significantly smaller amount of sets and I wouldn't have the storage issue I have now.