Given two lists:
list1 = ["a","b","c","d","e","f","b","c","b","d","f","c","b","e"]
list2 = ["b","c"]
with the assumption len(list2) == 2,
I was wondering how to get an output like this:
['a', 'bc', 'd', 'e', 'f', 'bc', 'b', 'd', 'f', 'c', 'b', 'e']
Essentially any instance of list2 within list1 (in that order), should concatenate in the original list1 and output (after checking all possibilities).
What I tried so far:
l = len(list1)
for i in range(0,l-1):
if list1[i] == list2[0]:
if list1[i+1] == list2[1]:
a = i
b = i+1
list1[a:b+1] = [''.join(list1[a:b+1])]
l = l - 1
print(list1)
But keep getting an error:
if list1[i] == list2[0]: IndexError: list index out of range