How do I remove items from a 2D list in Python?

Hello guys, I am writing a python code that will help organize sales data of a pizza joint. I am using a 2 Dimensional (2D) list for the project but having challenges deleting items from my list using the remove() method. Below is an excerpt of my code:

pizza_and_prices = [[2, "pepperoni"], [6, "pineapple"], [1, "cheese"], [3,"sausage"], [2, "olives"], [7, "anchovies"], [2, "mushrooms"]]

print(pizza_and_prices)

pizza_and_prices.sort()

print(pizza_and_prices)

cheapest_pizza = pizza_and_prices[0][1]

priciest_pizza = pizza_and_prices[-1][-1]

pizza_and_prices.remove([-1][-1])

This is the error message:

Traceback (most recent call last):
  File "script.py", line 18, in <module>
    pizza_and_prices.remove([-1][-1])
ValueError: list.remove(x): x not in list
2 Likes

My guess is that because -1 is not a valid index in the list you have

1 Like