Complete the code to select the pivot element as the last item in the list.
def quick_sort(arr): if len(arr) <= 1: return arr pivot = arr[[1]] left = [x for x in arr[:-1] if x <= pivot] right = [x for x in arr[:-1] if x > pivot] return quick_sort(left) + [pivot] + quick_sort(right)
The pivot is chosen as the last element, which is at index -1 in Python.
Complete the code to recursively sort the left partition of the list.
def quick_sort(arr): if len(arr) <= 1: return arr pivot = arr[-1] left = [x for x in arr[:-1] if x <= pivot] right = [x for x in arr[:-1] if x > pivot] return [1](left) + [pivot] + quick_sort(right)
The function calls itself recursively to sort the left partition.
Fix the error in the partitioning condition to correctly separate elements greater than the pivot.
def quick_sort(arr): if len(arr) <= 1: return arr pivot = arr[-1] left = [x for x in arr[:-1] if x <= pivot] right = [x for x in arr[:-1] if x [1] pivot] return quick_sort(left) + [pivot] + quick_sort(right)
Elements greater than the pivot go to the right partition, so the condition is >.
Fill both blanks to create a list comprehension that selects elements less than the pivot and squares them.
def process(arr): pivot = arr[-1] result = [x[1]2 for x in arr if x [2] pivot] return result
The expression squares elements (x ** 2) that are less than (<) the pivot.
Fill all three blanks to create a dictionary comprehension mapping each element to its square if it is greater than the pivot.
def map_squares(arr): pivot = arr[-1] result = { [1]: [2] for [3] in arr if [3] > pivot } return result
The dictionary maps each element x to its square x**2 if x is greater than the pivot.
