Learn Data Structures by Building the Merge Sort Algorithm - Step 11

Tell us what’s happening:

I am missing the nuance of the request. The while loop seems ok, but “an element” of the left_ or right_ part seems arbitrary, so I picked the first one…

Your code so far

def merge_sort(array):
    
    middle_point = len(array) // 2
    left_part = array[:middle_point]
    right_part = array[middle_point:]

    merge_sort(left_part)
    merge_sort(right_part)

    left_array_index = 0
    right_array_index = 0
    sorted_index = 0


# User Editable Region

    while left_array_index < len(left_part) and right_array_index < len(right_part)
        if left_part[1] < right_part[1]:
            array.append(left_part[1])
        else:
            array.append(right_part[1]) 

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn Data Structures by Building the Merge Sort Algorithm - Step 11

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Hello! @cojoMan

You’re almost there!

The code you’ve provided needs a few modifications…

  • loops too will have : like… while condition:

  • we need to use the pass keyword as the body of the loop

If you’re still stuck here is a hint:

Hint
while condition:
      pass

Happy Coding!

2 Likes

this was…not cool :))
thanks for the help, but the instructions said slightly otherwise, or I cannot read between the lines.

2 Likes

He’s right. It took me a while. I was looking at instructions and was scratching my head and I had to double check. All I had to do was go through the steps. The instructions need to be a little clearer imo.

1 Like