the sort function works the same way it sorts primarily by first elementbut in the case of tieit sorts by second elementand so on this feature lends itself to pattern called dsu for decorate sequence by building list of tuples with one or more sort keys preceding the elements from the sequencesort the list of tuples using the python built-in sortand undecorate by extracting the sorted elements of the sequence for examplesuppose you have list of words and you want to sort them from longest to shortesttxt 'but soft what light in yonder window breakswords txt split( list(for word in wordst append((len(word)word) sort(reverse=trueres list(for lengthword in tres append(wordprint(rescodethe first loop builds list of tupleswhere each tuple is word preceded by its length sort compares the first elementlengthfirstand only considers the second element to break ties the keyword argument reverse=true tells sort to go in decreasing order the second loop traverses the list of tuples and builds list of words in descending order of length the four-character words are sorted in reverse alphabetical orderso "whatappears before "softin the following list the output of the program is as follows['yonder''window''breaks''light''what''soft''but''in'of course the line loses much of its poetic impact when turned into python list and sorted in descending word length order