I have a list ['a', 'b', 'c', 'd'] and I need a list ['a', 'ab', 'abc', 'abcd', 'b', 'bc' , 'bcd', 'c', 'cd', 'd'].
I watched itertools , but I do not see how to do it.
For all combinations, the code will look like this:
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 do I need to do to return only sequential combinations? I think I could check the order for each permutation when I go, but that doesn't seem like the best way.
source share