I'm attempting to find a way for a given list to convert into multiple sub lists.
This works, however, the next thing I want is for the lists to only output when they are adjacent to one another. for example right now ['a','b','c']
outputs:
[],['a'],['b'],['c'],['a', 'b'],['a','c']
etc, I don't want ['a','c']
as they should not go next to each other. Can anyone point me in the right direction?
def list_thing(theList):
initial = []
lists = [initial]
for i in range(len(theList)):
original = lists[:]
new = theList[i]
for j in range(len(output)):
lists[j] = lists[j] + [new]
lists = lists + output
return lists
edit: To clarify, as I have been asked, I would also like ['a','b','c']
as they are a possible result.
Just to explain further ['a','b','c','d']
would give combos like ['a','b'], ['b','c'],['c','d'], ['a','b','c','d']
These would be acceptable answers.
While ['a','b','c'] ['a','c']
would not as they are not individually next to each other or part of the larger string.