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?
In general, your post will get a good answer if you’ve remembered to do the following:
Always search for existing answers first.
Provide as much information and context as possible.
Format your code.
Reference Additional Resources
Before Starting a Topic, Search for Existing Answers
Before you start a new topic, check existing posts and use Google to see if your questions have already been addressed. This will very often give you an immediate answer! Crypti…
How Can I be a Good Citizen of These Forums?
Use the guidelines below and FAQs to keep this a clean, well-lit place for civilized public discourse around learning new skills.
The following are are not hard and fast rules, but merely aids to your best judgment for navigating our community.
How Can I Improve the Discussion?
One way to improve the discussion is by discovering ones that are already happening.
Please spend some time browsing the topics here before replying or starting your own, …
This is the code I have so far. It added to the list, but has no brackets.
March 13, 2023, 10:45am
i is the index and
x is the item to be inserted.
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
pizza_and_prices.insert(4, [2.5, "peppers"])
April 24, 2023, 2:46am
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.