median of medians the median_of_medians function is responsible for finding the approximate median of any given list of items the function uses recursion to return the true mediandef median_of_medians(elems)sublists [elems[ : + for in range( len(elems) )medians [for sublist in sublistsmedians append(sorted(sublist)[len(sublist)/ ]if len(medians< return sorted(medians)[len(medians)/ elsereturn median_of_medians(mediansthe function begins by splitting the listelemsinto groups of five elements each this means that if elems contains itemsthere will be groups created by the statement sublists [elems[ : + for in range( len(elems) )]with each containing exactly five elements or fewermedians [for sublist in sublistsmedians append(sorted(sublist)[len(sublist)/ ]an empty array is created and assigned to medianswhich stores the medians in each of the five element arrays assigned to sublists the for loop iterates over the list of lists inside sublists each sublist is sortedthe median foundand stored in the medians list the medians append(sorted(sublist)[len(sublist)/ ]statement will sort the list and obtain the element stored in its middle index this becomes the median of the fiveelement list the use of an existing sorting function will not impact the performance of the algorithm due to the list' small size we understood from the outset that we would not sort the list in order to find the ith-smallest elementso why employ python' sorted methodwellsince we are sorting very small list of five elements or fewerthe impact of that operation on the overall performance of the algorithm is considered negligible