Asked • 04/19/19

Is there a simple way to delete a list element by value?

a=[1,2,3,4] b=a.index(6) del a[b] print aThe above shows the following error:<!-- language: lang-none --> 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 listSo I have to do this: a=[1,2,3,4] try: b=a.index(6) del a[b] except: pass print aBut is there not a simpler way to do this?

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.