Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
List basics
10. Deleting elements by value
Lists with if statements and loops
Lists in functions
Summary

Instruction

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
companies.remove('Total')

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

Exercise

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.