I have two lists:
big_list = [2, 1, 2, 3, 1, 2, 4]
sub_list = [1, 2]
I want to remove all sub_list occurrences in big_list.
result
A improved version to check whether lst[i:i+len(sub)] < len(lst)
def remove_sublist(lst, sub):
i = 0
out = []
sub_len = len(sub)
lst_len = len(lst)
while i < lst_len:
if (i+sub_len) < lst_len:
if lst[i: i+sub_len] == sub:
i += sub_len
else:
out.append(lst[i])
i += 1
else:
out.append(lst[i])
i += 1
return out