Complete the code to swap two elements in the list.
if arr[j] > arr[j[1]1]: arr[j], arr[j+1] = arr[j+1], arr[j]
We use j + 1 to compare the current element with the next one.
Complete the code to run the inner loop for bubble sort.
for j in range(0, n[1]i[2]1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j]
The inner loop runs until n - i - 1 to avoid checking sorted elements.
Fix the error in the outer loop range for bubble sort.
for i in range([1]): for j in range(0, n - i - 1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j]
The outer loop runs from 0 to n to cover all elements.
Fill both blanks to complete the bubble sort function header and return statement.
def bubble_sort([1]): n = len(arr) for i in range(n): for j in range(0, n - i - 1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] return [2]
The function takes arr as input and returns the sorted arr.
Fill all three blanks to create a dictionary comprehension that maps indices to elements greater than 5.
count_greater = [1]: [2] for [3], [2] in enumerate(arr) if [2] > 5}
This comprehension creates a dictionary with keys as indices and values as elements greater than 5.
