def findMedian(lst): if len(lst) == 0: return None if len(lst) % 2 == 0: num1 = findKth(lst, len(lst)//2) num2 = findKth(lst, len(lst)//2 - 1) num = (num1 + num2) * 1.0 / 2 else: num = findKth(lst, len(lst)//2)
print("result: " + str(num)) return num
def findKth(lst, k): if len(lst) == 0: return None
if len(lst) == 1: return lst[0]
medians = [] for i in range(0, len(lst), chunkSize): chunk = lst[i:min(i + chunkSize, len(lst))] chunk.sort() median = chunk[len(chunk)//2] medians.append(median)