Also, a pass statement is almost always unnecessary
word_list=['the','i','am','light','life'] a=sorting(word_list) def sorting(x): for i in range(1, len(word_list)): if len(x[i-1]) > len(x[i]): temp=x[i+1] x[i+1]=x[i] x[i]=temp