notice that since python functions are objects like any otherthey can be passed as arguments to other functionsand stored in collections without formality recall that function' name is an object reference to the functionit is the parentheses that follow the name that tell python to call the function when key function is passed (in this case the abs(function)it is called once for every item in the list (with the item passed as the function' sole parameter)to create "decoratedlist then the decorated list is sortedand the sorted list without the decoration is returned as the result we are free to use our own custom function as the key functionas we will see shortly for examplewe can case-insensitively sort list of strings by passing the str lower(method as key if we have the listxof ["sloop""yawl""cutter""schooner""ketch"]we can sort it case-insensitively using dsu (decoratesortundecoratewith single line of code by passing key functionor do the dsu explicitlyas these two equivalent code snippets showx sorted(xkey=str lowertemp [for item in xtemp append((item lower()item) [for keyvalue in sorted(temp) append(valueboth snippets produce new list["cutter""ketch""schooner""sloop""yawl"]although the computations they perform are not identical because the right-hand snippet creates the temp list variable python' sort algorithm is an adaptive stable mergesort that is both fast and smartand it is especially well optimized for partially sorted lists-- very common case the "adaptivepart means that the sort algorithm adapts to circumstances--for exampletaking advantage of partially sorted data the "stablepart means that items that sort equally are not moved in relation to each other (after allthere is no need)and the "mergesortpart is the generic name for the sorting algorithm used when sorting collections of integersstringsor other simple types their "less thanoperator (<is used python can sort collections that contain collectionsworking recursively to any depth for examplex list(zip(( )("pram""dorie""kayak""canoe")) [( 'pram')( 'dorie')( 'kayak')( 'canoe')sorted( [( 'kayak')( 'pram')( 'canoe')( 'dorie')the algorithm was created by tim peters an interesting explanation and discussion of the algorithm is in the file listsort txt which comes with python' source code