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 recursive approach:
def remove(lst, sub): if not lst: return [] if lst[:len(sub)] == sub: return remove(lst[len(sub):], sub) return lst[:1] + remove(lst[1:], sub) print(remove(big_list, sub_list))
This outputs:
[2, 3, 4]