advanced sorting listing implementation of the quick sort algorithm sorts an array or list using the recursive quick sort algorithm def quicksorttheseq ) lentheseq recquicksorttheseq - the recursive implementation using virtual segments def recquicksorttheseqfirstlast )check the base case if first >last return else save the pivot value pivot theseq[firstpartition the sequence and obtain the pivot position pos partitionseqtheseqfirstlast repeat the process on the two subsequences recquicksorttheseqfirstpos recquicksorttheseqpos last partitions the subsequence using the first key as the pivot def partitionseqtheseqfirstlast )save copy of the pivot value pivot theseq[firstfind the pivot position and move the elements around the pivot left first right last while left <right find the first key larger than the pivot while left right and theseq[leftpivot left + find the last key in the sequence that is smaller than the pivot while right >left and theseq[right>pivot right - swap the two keys if we have not completed this partition if left right tmp theseq[lefttheseq[lefttheseq[righttheseq[righttmp put the pivot in the proper position if right !first theseq[firsttheseq[righttheseq[rightpivot return the index position of the pivot value return right