The easiest way to explain this problem is to show these two test cases:
assert solution('ABC') == ['A', 'B', 'C', 'AB', 'AC', 'BC', 'ABC']
assert solution('ABCD') == ['A', 'B', 'C', 'D', 'AB', 'AC', 'AD', 'BC', 'BD', 'CD', 'ABC', 'ABD', 'ACD', 'BCD', 'ABCD']
my solution is below:
def subsolution(lst, length):
return [lst + [x] for x in·
range(lst[-1]+1, length)]
def solution(symbols):
length = len(symbols)
result = [[[x] for x in range(length)]]
while True:
subres = []
for x in result[-1]:
subres.extend(subsolution(x, length))
if not subres:
break
result.append(subres)
result = [ item for sublist in result
for item in sublist
]
result = [
''.join(symbols[s] for s in el)
for el in result
]
return result