Lens slice exercise

I am trying to .insert into a 2D list, and the end of script.py but I’m stuck. Codecademy export · GitHub

Traceback (most recent call last):
File “script.py”, line 21, in
pizza_and_prices.insert(3, 2.5, “peppers”)
TypeError: insert() takes exactly 2 arguments (3 given)

Since the new pizza has a price of 2.5 , it should come after [2, "pepperoni"] but before [3, "sausage"] .

You can use the .insert() method to insert an element at a specific index.

If you intend to insert a list make sure you pass a list [2.5, "peppers"] is different to 2.5, "peppers" as the second is treated as additional arguments in this example.

1 Like

PERFECT. Thank you very much!!!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.