Learn

Our merge_sort() function so far only separates the input list into many different parts — pretty much the opposite of what you’d expect a merge sort to do. To actually perform the merging, we’re going to define a helper function that joins the data together.

Instructions

1.

Define the function merge(), which is going to take care of merging our two lists together. It should take two parameters: left and right. These are going to be the two (sorted) lists we want to merge.

2.

Instantiate a new empty list and call it result. We’re going to add members of left and right to result until it contains a sorted list with all elements of both.

Return result at the end of the function.

Sign up to start coding

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?