I've got a list ['a', 'b', 'c', 'd'] and I need a list ['a', 'ab', 'abc', 'abcd', 'b', 'bc', 'bcd', 'c', 'cd', 'd'].
I've been looking at itertools, but I'm not seeing how to make this work.
For all combinations, the code would be:
from itertools import permutations
stuff = ['a','b','c','d']
for i in range(0, len(stuff)+1):
for subset in permutations(stuff, i):
print(subset)
What would I need to do to return only sequential combinations? I guess I could check the order for each permutation as I go, but that doesn't seem to be the best way.
'abc'and'd'there as well? Because otherwise I don't see any logic in your list.'abc'also be in the list you want to construct?print([''.join(stuff[i:j]) for i in range(len(stuff)) for j in range(i+1, len(stuff)+1)])