I need help to generate all possible subsets of given letters in Python.
For instance:
List=['a','b','c']
Subset=['a','b','c','ab','ac','bc','abc']
I need help to generate all possible subsets of given letters in Python.
For instance:
List=['a','b','c']
Subset=['a','b','c','ab','ac','bc','abc']
From the input and output you have given the following code will work for you,
Code:
list1=['a','b','c']
sublist = list()
for i in range(len(list1)):
for j in range(i+1, len(list1)+1):
sub = list1[i:j]
s1=""
for j in sub:
s1+=j
sublist.append(s1)
print(sublist)
Output:
['a', 'ab', 'abc', 'b', 'bc', 'c']