Problem with inserting in Python: List in Len's slice

Please see the screenshot below. I get this error message, but what should I do about the float?

This is the link to the exercise:

Haven’t checked or anything but, at a first glance, I’d say that it needs an index and should should be a list, so like .insert(4, [2.5, "peppers"]) because you’re meant to be adding a list (as shown in the instructions - note the brackets), not a float and a string, and there’s the note about positioning to determine which index.

Of course, I’ve not actually done this, so I may be totally wrong, but that’s what it looks like.



You get this error because the .insert() method takes the arguments in the following order
list_name.insert(index, element)
As you’d expect, the index must be an int and in your case a float is being passed. To fix your code, try this:

pizza_and_prices.insert(0, [2.5, 'anchovies']) 

Doing so, will add the element [2.5m ‘anchovies’] in the beginning of your list.

1 Like