Help with Lens Slice Project

I’m having trouble inserting a new element to my 2-D list called pizza_and_prices. How do I use .insert() to add an element for a 2-d list. I’m confused.

Please post your formatted code.
But also, do a quick search on the forums. There are 50+ threads on this very topic. Perhaps one of them can help?

and,

1 Like

This is the code I have so far. It added to the list, but has no brackets.
pizza_and_prices.insert(4,“2.5, peppers”)

list.insert(i, x)

where i is the index and x is the item to be inserted.

You wrote:

pizza_and_prices.insert(4,"2.5, peppers")

You are inserting the string "2.5, peppers" at index 4.

But the item you want to insert is not meant to be a string. It is meant to be a list of two elements with the first element being a number and the second being a string i.e. you want to insert the element [2.5, "peppers"]

pizza_and_prices.insert(4, [2.5, "peppers"])

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