-
Python TypeError: object of type 'NoneType' has no len()
over 7 years ago
-
about 7 years ago
can you send me the file so i can run it my machine then i will check and make it correct and send it to you . -
-
about 7 years ago
The error is that merge() does not return anything (returns implicitly None), but its return value is returned by merge_sort(). Hence, checking the length of a None.
Also, print_it() uses print output, but output is not initialized in the scope of the function. -
-
about 7 years ago
Hi, the code you were using is correct, only the issue is of "indentation error" which comes because of IDE you were using, I am using pycharm IDE. You can use this code:A=[31,22,14,15] def merge(list1,list2): output=[] i=0 j=0 length1=len(list1) length2=len(list2) while i<length1 or j<length2: if i<length1 and j<length2: if list1[i] < list2[j]: output +=[list1[i]] i +=1 else: output +=[list2[j]] j +=1 elif i<length1: output +=[list1[i]] i +=1 else: output +=[list2[j]] j+=1 def merge_sort(list1): if len(list1)<=1: return list1 else: mid=int(len(list1)/2) left =list1[:mid] right=list1[mid:] sorted_left=merge_sort(left) sorted_right=merge_sort(right) return merge(sorted_left,sorted_right) def print_it(lista): merge_sort(lista) print "OutPut : ",output print_it(A)
-
3 Answer(s)