Number of possible combinations for the given Indices
for example the indice[0] of the word BANANA
should give me :
{'B',
'BA',
'BAN',
'BANA',
'BANAN',
'BANANA'}
word='BANANA'
indices=[0,2,4]
def find_combinations(word:str,indices:list):
a=[''.join(l) for i in range(len(word)) for l in combinations(word, i+1)]
b=[x for x in a if x.startswith('B')]
return b
output:
set(b)
{'B',
'BA',
'BAA',
'BAAA',
'BAAN',
'BAANA',
'BAN',
'BANA',
'BANAA',
'BANAN',
'BANANA',
'BANN',
'BANNA',
'BN',
'BNA',
'BNAA',
'BNAN',
'BNANA',
'BNN',
'BNNA'}
desired output:
{'B',
'BA',
'BAN',
'BANA',
'BANAN',
'BANANA'}