Len's Slice - Error when Appending a Float value

In the Len’s Slice Exercise, I get an error when attempting to append [2.5, “peppers”] to a pre-existing 2D array.

toppings = ["pepperoni", "pineapple", "cheese", "sausage", "olives", "anchovies", "mushrooms"] prices = [2.0, 6.0, 1.0, 3.0, 2.0, 7.0, 2.0] pizza_and_prices = list(zip(prices,toppings)) pizza_and_prices.insert( 2.5,"peppers")

I get the following error

Blockquote
Traceback (most recent call last):
File “script.py”, line 31, in
pizza_and_prices.insert( 2.5,“peppers”)
TypeError: integer argument expected, got float

Blockquote

Any ideas?

Hello, there!
Are you sure you’re attempting to append…

you’re using insert on line 4, which is trying to use the 2.5 as a index - hence the error

Thank you! Your comment pointed me in the right direction, as I was indeed misusing the append function here. The correct format would be:
pizza_and_prices.insert(4,(2.5,“peppers”))
Merci!

1 Like

A post was split to a new topic: Stuck on #5