Question: Code below is using the Merge sort algorithm. However, Keep getting an error that L is not defined when I call the main function. HELP.

Code below is using the Merge sort algorithm. However, Keep getting an error that "L is not defined" when I call the main function. HELP. I want to have to return the final sorted list. (Use python 3)

(I also want to print the L1, and L2, )

def random_list (n): L = [] for i in range(n): L.append(random.randrange(0, 366)) return L

def sort_merge(L): n =Llen(L) if (n == 0 or n == 1): return L else: m = len(L)//2 L1 = sort_merge(L[:m]) L2 = sort_merge(L[m:]) return sort_merge_merging(L1,L2)

def sort_merge_merging (L1, L2): good = [] i = 0 j = 0 while True: if (i == len(L1)) and (j == len(L2)): break elif (i != len(L1) and j != len(L2)): if (L1[i] <= L2[j]): good.append(L1[i]) i = i + 1 else: good.append(L2[j]) j = j + 1 elif (j == len(L2)): good.append(L1[i]) i = i + 1 elif (i == len(L1)): good.append(L2[j]) j = j + 1

return good

print(sort_merge(L))

Traceback (most recent call last): File "/Users/andry/Documents/sorting.py", line 79, in print(sort_merge(L)) NameError: name 'L' is not defined

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!