class Solution:
def sort(self,data):
list=[]
for item in data:
list.append([item])
while len(list)>1:
templist=[]
m = len(list)
if len(list) % 2 == 0:
for i in range(0,m - 1, 2):
templist.append(self.merge(list[i],list[i+1]))
else:
for i in range(0,m-2,2):
templist.append(self.merge(list[i],list[i+1]))
templist.append(list[-1])
list.clear();
list=templist[:]
return list
def merge(self,data1,data2):
list=[]
a1=0
a2=0
while len(list)<len(data1)+len(data2):
if a1>len(data1)-1 :
list.append(data2[a2])
a2+=1
pass
elif a2>len(data2)-1 :
list.append(data1[a1])
a1+=1
pass
elif data1[a1]<=data2[a2]:
list.append(data1[a1])
a1+=1
pass
else:
list.append(data2[a2])
a2+=1
pass
pass
return list
s1= Solution()
data=[4,5,2,3,6,7,6,34,25,15]
print(s1.sort(data))