0
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?

Taku
  • 31,927
  • 11
  • 74
  • 85
Phoebe
  • 57
  • 1
  • 6

1 Answers1

0

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:]
DYZ
  • 55,249
  • 10
  • 64
  • 93
  • Note that I incorrectly used `start+end` instead of `end` in the last line, and it worked because `start==0`. The answer is now fixed. – DYZ Apr 02 '17 at 06:33