List basics
10. Deleting elements by value
Lists with if statements and loops
Lists in functions


Excellent. Another way to delete an item from a list is when you know the value but not the index. In that case use list_name.remove(element):

# define a list
companies = ['Royal Dutch Shell', 'BP', 'Total', 'Volkswagen', 'Glencore Xstrata', 'Gazprom']

# delete Total

Behind the curtains, remove(...) also shifts all elements with higher indices to avoid empty spaces.


Again, get rid of the first element in the list. This time, delete by value (730). Print the list afterwards.

Stuck? Here's a hint!

Use water_level.remove(...). Inside the brackets, put the value you want to get rid of.