I was writing a Python program to generate all possible substrings of a given input string using itertools.
def substring_generator(seq):
substring_list = list(seq)
return chain.from_iterable(combinations(substring_list, r) for r in range(len(seq) + 1))
print list(map(''.join, substring_generator('LLRR')))
to output ['', 'L', 'L', 'R', 'R', 'LL', 'LR', 'LR', 'LR', 'LR', 'RR', 'LLR', 'LLR', 'LRR', 'LRR', 'LLRR']. But I was wondering how I could also output the indices for each character in the substring e.g. seq = L0L1R2R3 a substring would be L0R2 or L1R2R3 Is there any way I could do this without having to edit too much of the existing code?