Need help in this Python Exercise

Hello i do need help for this exercise,.

pizza_and_prices = [[1, ‘cheese’], [2, ‘mushrooms’], [2, ‘olives’], [2, ‘peperoni’], [3, ‘sausage’], [6, ‘pineapple’]]

well, i do have to insert inside of (pizza_and_prices) the next : [2.5, “peppers”] and has to be sorted, but when i try to add 2.5 "peppers, it says that it must to be and integer or a string, not a float numer, any idea how to add it ? THANKS

you have to find what the correct index would be and insert it using that instead of using 2.5

1 Like

Hey thanks for your answer, could you give me some clue? Thanks

The built-in list method, .insert() takes two parameters—the index at where you want to insert the element and the element you’re inserting into the list.

So…the question asks that you insert the items at index 4…

pizza_and_prices.insert(__, _____)


1 Like

I did this, maybe its wrong?

new_pizza = [2.5, “peppers”]

pizza_and_prices.insert(4, new_pizza)


I tried to do as you say but, insert command just lets me add 2 things, so when I wanted to add 2.5 “peppers” in the fourth element it didn’t let me

[2.5, “peppers”] is the second parameter, or, argument that you’re inserting.

pizza_and_prices is comprised of smaller lists that are nested inside the larger list. So, one can insert a list into the larger list.

[[1, 'cheese'], [2, 'mushrooms'], [2, 'olives'], [2, 'pepperoni'], [3, 'sausage'], [6, 'pineapple'], [7, 'anchovies']]

pizza_and_prices.insert(4, [______])

It might be a good idea to review nested lists and how one accesses them. I think at this point in the lessons it has been covered.


Thanks for answering lisalisaj !

1 Like