Learn

After a list is created, we can add things to it.

When we add things to the end of an existing list, we say that we’re appending them to the end.

Imagine we have a list of fruit that contains "Apples", "Bananas", and "Pears". When we append the value "Mangos", the list would contain "Apples", "Bananas", "Pears", and "Mangos". Notice how "Mango" is at the end.

In addition to adding things to the end of a list, we can also insert items into the existing list. We do so by using the index number for where we want to position our new value.

Our list now contains "Apples", "Bananas", "Pears", and "Mangos". Now imagine we add "Kiwis" at index 1. This would add "Kiwis" between "Apples" and "Bananas". After the addition, our list would contain "Apples", "Kiwis", "Bananas", "Mangos", and "Pears".

It’s important to be careful - adding something in the middle of a pre-existing list, or adding it to the beginning of a list, will alter the indices for all the following items. Notice that "Bananas" were in the second position and are now in the third.

Instructions

Use the new add at index or append command to make the list on the left match the list on the right.

Hint
Blue needs to be added to the middle of the list, and red needs to be added to the end. Append can be used to add to the end.
Solution
Add blue at index 1 Append red

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?