def sort_func(left,right): if left<right: return -1 if left>right: return 1 return 0 list_test=[2,1,9,1,4] list_test.sort(sort_func) #list_test=sorted(list_test,sort_func) print list_test