last sort tuplesc:\pp \dstruct\classicspython sort py [{'age' 'name''doe'}{'age' 'name''john'}[{'age' 'name''john'}{'age' 'name''doe'}[('doe' )('john' )[('john' )('doe' )adding comparison functions since functions can be passed in like any other objectwe can easily allow for an optional comparison function in the next versionexample - the second argument takes function that should return true if its first argument should be placed before its second lambda is used to provide an ascending-order test by default this sorter also returns new sequence that is the same type as the sequence passed inby applying the slicing techniques used in the reversal tools earlier--if you sort tuple of nodesyou get back tuple example - pp \dstruct\classics\sort py def sort(seqfunc=(lambda ,yx < ))res seq[: for in range(len(seq)) for in resif func(seq[ ] )break + res res[:iseq[ : + res[ :return res defaultascending return seq' type seq can be immutable if __name__ ='__main__'table ({'name':'doe'}{'name':'john'}print(sort(list(table)(lambda xyx['name' ['name']))print(sort(tuple(table)(lambda xyx['name'< ['name']))print(sort('axbyzc')this timethe table entries are ordered per field comparison function passed inc:\pp \dstruct\classicspython sort py [{'name''john'}{'name''doe'}({'name''doe'}{'name''john'}abcxyz this version also dispenses with the notion of field altogether and lets the passed-in function handle indexing if needed that makes this version much more generalfor instanceit' also useful for sorting strings data structures versus built-insthe conclusion but now that 've shown you these reversing and sorting algorithmsi need to also tell you that they may not be an optimal approachespecially in these specific cases data structures