I couldn’t find the answer to this anywhere, nor any code examples to relate to.
I am stuck on Learn Python 3 - Len’s Slice - Q12:
Since there is no longer an
"anchovies" pizza, you want to add a new topping called
"peppers" to keep your customers excited about new toppings. Here is what your new topping looks like:
* *[2.5, "peppers"]* *
Add the new peppers pizza topping to our list
Note: Make sure to position it relative to the rest of the sorted data in
pizza_and_prices , otherwise our data will not be correctly sorted anymore!
I am struggling to adhere to inserting at both the elements, what I have at present is:
My problem is at “pizza_and_prices.insert(2.5, “peppers”)” in which fails as my inner list is composed of integers and not floats: (do I have to manipulate the value, similar to “str”?)
Traceback (most recent call last):
** File “script.py”, line 24, in **
** pizza_and_prices.insert(2.5, “peppers”)**
TypeError: integer argument expected, got float
If I change it to an Int, it does index at the correct value but I am not sure how to insert both arguments with an index of 2.