Lists: Difficult
LIST FUNCTIONS
Draw out a box and pointer diagram for lst1 and lst2.
lst1 = [1, 2, 3, 4]
lst2 = [5, 6, 7, 8]
lst1[lst2[0] - lst1[1]] = lst2
lst2.append(lst1.remove(2))
lst1.extend([lst2[len(lst1)]])
lst2.append([lst1[len(lst1) - lst1[2][0] + lst1[lst1[0]]]])
code Writing
Write a function that will take in a list and sort it using quicksort. Quicksort takes the first element and partitions the list into three partitions: elements less than the first element, elements equal to the first element, and elements greater than the first element. Then it recursively applies those steps to the partitions.
def quicksort(lst):
>>> lst = [4, 6, 7, 2, 1, 3]
>>> quicksort(lst)
[1, 2, 3, 4, 6, 7]
if ______:
return ______
less = ______
equal = ______
greater = ______
______
______
return ______