a = [0, 0, 0, 0, 1, 0, 0]
b = [0, 0, 0, 0]
I want to remove the [0, 0, 0, 0]
from list a.
How do I do this?
a = [0, 0, 0, 0, 1, 0, 0]
b = [0, 0, 0, 0]
I want to remove the [0, 0, 0, 0]
from list a.
How do I do this?
Convert each list to a string:
a1 = ''.join('1' if x else '0' for x in a)
b1 = ''.join('1' if x else '0' for x in b)
Find the start index of b1
in a1
:
start = a1.index(b1)
The end index is start
index plus the length of b1
:
end = start + len(b1)
Now, extract the original list fragments before start
and after end
and combine them:
newlist = a[:start] + a[end:]