Newbie here. Writing function that prints out all the subsets of a set using generator (yield statement). The problem is, I cannot make it so that it uses yield and works for sets of all lenghts, not only three, like in my code below. I can make it work for 4 and 5 obviously, but the ladder gets bigger, which is just ridiculous, let alone pythonic and elegant.
ABC = ['a', 'b', 'c']
def subsets(group):
for i in [group[0], []]:
for j in [group[1], []]:
for k in [group[2], []]:
yield filter(None, [i, j, k])
for element in subsets(ABC):
print element
The output (for this 3-item list) should be:
['a', 'b', 'c']
['a', 'b']
['a', 'c']
['a']
['b', 'c']
['b']
['c']
[]