Let say I have a list like this with n elements:
myList = ['cr','cd','cs','sp','sd','op','ol','fs','th','ag','ng','rt','bp']
I want to remove one element in the list every time while iterating then combine iteratively the other elements in my list to have an output like this:
# removing the first element, we would have:
['cd']
['cd', 'cs']
['cd', 'cs', 'sp']
['cd', 'cs', 'sp', 'sd']
['cd', 'cs', 'sp', 'sd', 'op']
['cd', 'cs', 'sp', 'sd', 'op', 'ol']
['cd', 'cs', 'sp', 'sd', 'op', 'ol', 'fs']
['cd', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th']
['cd', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag']
['cd', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag', 'ng']
['cd', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag', 'ng', 'rt']
['cd', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag', 'ng', 'rt', 'bp']
# Then removing the second element, we would have:
['cr']
['cr', 'cs']
['cr', 'cs', 'sp']
['cr', 'cs', 'sp', 'sd']
['cr', 'cs', 'sp', 'sd', 'op']
['cr', 'cs', 'sp', 'sd', 'op', 'ol']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag', 'ng']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag', 'ng', 'rt']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag', 'ng', 'rt', 'bp']
# Removing ith element:
........
I have tried like this removing manually one element each time:
# 2nd element is removed
myList = ['cr','cs','sp','sd','op','ol','fs','th','ag','ng','rt','bp']
for i in range(1, len(myList) + 1):
input_f = myList[:i]
print(input_f)
and get this result:
['cr']
['cr', 'cs']
['cr', 'cs', 'sp']
['cr', 'cs', 'sp', 'sd']
['cr', 'cs', 'sp', 'sd', 'op']
['cr', 'cs', 'sp', 'sd', 'op', 'ol']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag', 'ng']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag', 'ng', 'rt']
['cr', 'cs', 'sp', 'sd', 'op', 'ol', 'fs', 'th', 'ag', 'ng', 'rt', 'bp']
This puts me one step closer but I can not figure out how to to handle the rest automatically. Any idea would be appreciated.