fork(1) download
  1. def remove_sublist(lst, sub):
  2. i = 0
  3. out = []
  4. while i < len(lst):
  5. if lst[i:i+len(sub)] == sub:
  6. i += len(sub)
  7. else:
  8. out.append(lst[i])
  9. i += 1
  10. return out
  11.  
  12. print(remove_sublist([1, 'a', int, 3, float, 'a', int, 5], ['a', int]))
Success #stdin #stdout 0.04s 9420KB
stdin
Standard input is empty
stdout
[1, 3, <class 'float'>, 5]