FAQ: Merge Sort: Python - Finishing the Merge

This community-built FAQ covers the “Finishing the Merge” exercise from the lesson “Merge Sort: Python”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Sorting Algorithms

FAQs on the exercise Finishing the Merge

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Is it valid?

while (left and right):
    result.append(left.pop(0) if left[0] < right[0] else right.pop(0))
  result.extend(left or right)
  return result

Maybe not valid because I haven’t seen this syntax before(now I’ve seen it).
result.extend(left or right)
What kind of thing is that?

I tried to solve this using result.extend(left or right), but the tests failed with the extend function and forced me to use += (in-place add). I started wondering if there was any advantage to += over .extend method and actually found that the .extend method is faster for concatenating two lists than the +=. Wonder why += was preferred over extend method

Hello, so I’m confused why the while loop and if statements don’t use any comparisons. Like when I was going through the practice problems, I knew I had to loop through the while loop while left and right were not empty (meaning the length of these lists were not equal to 0). So what’s the difference between the two following pieces of code:

while (left and right) and while (len(left) and len(right)) !=0

Also, why would the second one be wrong if I want to loop through the lists until all elements have been checked?

Thank you!