I'm trying to get all combinations of a list where two elements next to each other may "become one". For example;
>>> list = ['a', 'b', 'c', 'd']
>>> get_comb(list)
[['ab', 'c' 'd'], ['a', 'bc' 'd'], ['a', 'b', 'cd'] ['ab', 'cd']]
The tricky part is that two elements can become one, and I've been stuck on this problem for a long time. I tried something like this;
list_split_up = [list[i:i+2] for i in range(0, len(list), 2)]
indexes = [str(i) for i in range(len(list_split_up)) if len(list_split_up[i])==2]
comb = [''.join(l) for i in range(len(indexes),0,-1) for l in itertools.combinations(indexes, i)]
where I get all the indexes of possible combinations, and with that I can get create what I want - but the problem is that it only gives me combinations like ['ab', 'cd'] (because I split the list into two and two), and I therefore won't get i.e. ['a', 'bc', 'd'], as I want.