accomplish what we just did the hard waybuilt-in sorting tools python' two built-in sorting tools are so fast that you would be hard-pressed to beat them in most scenarios to use the list object' sort method for arbitrary kinds of iterablesconvert first if neededtemp list(sequencetemp sort(use items in temp alternativelythe sorted built-in function operates on any iterable so you don' need to convertand returns new sorted result list so you can use it within larger expression or context because it is not an in-place changeyou also don' need to be concerned about the possible side effects of changing the original listfor item in sorted(iterable)use item for custom sortssimply pass in the key keyword arguments to tailor the built-in sort' operation--it maps values to sort keys instead of performing comparisonsbut the effect is just as general (see the earlier graph searcherslength ordering for another example) [{' ': }{' ': }{' ': }{' ': } sort(key=lambda xx[' '] [{' ' }{' ' }{' ' }{' ' }both sorting tools also accept boolean reverse flag to make the result order descending instead of ascendingthere is no need to manually reverse after the sort the underlying sort routine in python is so good that its documentation claims that it has "supernatural performance"--not bad for sort built-in reversal tools our reversal routines are generally superfluous by the same token--because python provides for fast reversals in both in-place and iterable formsyou're likely better off using them whenever possiblel [ reverse( [ [ list(reversed( )[ in factthis has been recurring theme of this on purposeto underscore key point in python workalthough there are plenty of exceptionsyou're generally better reversing and sorting sequences