fork download
  1. from functools import reduce
  2.  
  3. def remove_sublist(big_list, sub_list):
  4. result = reduce(lambda r, x: r[:1]+([1]+r[2:-r[1]],[min(len(r[0]),r[1]+1)]+r[2:])[r[-r[1]:]!=r[0]]+[x], big_list+[0], [sub_list, 1])[2:-1]
  5. print("remove_sublist(%s, %s) == %s" % (big_list, sub_list, result))
  6. return result
  7.  
  8.  
  9. remove_sublist([], [1, 2])
  10. remove_sublist([2, 1, 2, 3, 1, 2, 4], [1])
  11. remove_sublist([2, 1, 2, 3, 1, 2, 4], [1, 2])
  12. remove_sublist([2, 1, 2, 3, 1, 2, 4], [2, 1])
  13. remove_sublist([2, 1, 2, 3, 1, 2, 4], [2, 3, 1])
  14. remove_sublist([2, 1, 2, 3, 1, 2, 4, 1, 2], [1, 2])
  15. remove_sublist([1, 2, 3, 1, 2, 4, 1, 2], [1, 2])
  16. remove_sublist([1, 1, 2, 2, 3, 1, 2, 4], [1, 2])
  17.  
Success #stdin #stdout 0.03s 9280KB
stdin
Standard input is empty
stdout
remove_sublist([], [1, 2]) == []
remove_sublist([2, 1, 2, 3, 1, 2, 4], [1]) == [2, 2, 3, 2, 4]
remove_sublist([2, 1, 2, 3, 1, 2, 4], [1, 2]) == [2, 3, 4]
remove_sublist([2, 1, 2, 3, 1, 2, 4], [2, 1]) == [2, 3, 1, 2, 4]
remove_sublist([2, 1, 2, 3, 1, 2, 4], [2, 3, 1]) == [2, 1, 2, 4]
remove_sublist([2, 1, 2, 3, 1, 2, 4, 1, 2], [1, 2]) == [2, 3, 4]
remove_sublist([1, 2, 3, 1, 2, 4, 1, 2], [1, 2]) == [3, 4]
remove_sublist([1, 1, 2, 2, 3, 1, 2, 4], [1, 2]) == [1, 2, 3, 4]