def switch(n):
temp = 0
for each in str(n):
temp += int(each)
if temp < 10:
return temp
else:
return switch(temp)
def cus_sort(list_o):
for i in range(len(list_o)-1):
for j in range(len(list_o)-i-1):
if list2.index(list_o[j]) > list2.index(list_o[j+1]):
list_o[j], list_o[j+1] = list_o[j+1], list_o[j]
return list_o
list3 = []
for each in list1:
list3.append(switch(each))
print(cus_sort(list3))