I am manipulating a set, so if you have a set(aka:list) of n distinctive elements, then you have 2^n subset. Here I show how:
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]
l = list(powerset(["A", "B"]))
print(l)
which gives:
[[], ['A'], ['B'], ['A', 'B']]
Now how can take the above list eliminate the empty list, and merge the last element such that it becomes:
['A', 'B', 'AB']
I want to repeat this procedure 5 times, taking final output and write its sublist, eliminate the empty list and merge those elements that they fall into the same sublist.