[Solved-3 Solutions] Is there a simple way to delete a list element by value?
Error Description:
- The above shows the following error:
Solution 1:
- To remove an element's first occurrence in a list, simply use list.remove:
- Mind that it does not remove all occurrences of your element. Use a list comprehension for that.
Solution 2:
- Usually Python will throw an Exception if you tell it to do something it can't so you'll have to do either:
- or:
Solution 3:
- You can do
- but above need to search 6 in list a 2 times, so try except would be faster