<s>[INST] Is there a simple way to delete a list element by value in python? a=[1,2,3,4]
b=a.index(6)
del a[b]
print a

The above shows the following error:
Traceback (most recent call last):
  File "D:\zjm_code\a.py", line 6, in <module>
    b=a.index(6)
ValueError: list.index(x): x not in list

So I have to do this:
a=[1,2,3,4]
try:
    b=a.index(6)
    del a[b]
except:
    pass
print a

But is there not a simpler way to do this?
 [/INST] To remove an element's first occurrence in a list, simply use list.remove:
>>> a = ['a', 'b', 'c', 'd']
>>> a.remove('b')
>>> print a
['a', 'c', 'd']

Mind that it does not remove all occurrences of your element. Use a list comprehension for that.
>>> a = [1, 2, 3, 4, 2, 3, 4, 2, 7, 2]
>>> a = [x for x in a if x != 2]
>>> print a
[1, 3, 4, 3, 4, 7]

 </s>