has any simply way to delete a value in list of python

Posted by zjm1126 on Stack Overflow See other posts from Stack Overflow or by zjm1126
Published on 2010-05-08T07:48:28Z Indexed on 2010/05/08 7:58 UTC
Read the original article Hit count: 213

Filed under:
|
|
|
a=[1,2,3,4]
b=a.index(6)
del a[b]
print a

it show 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 this is not simple,has any simply way ?

thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about list