Complete the code to sort the list in ascending order.
numbers = [5, 3, 8, 1, 2] numbers.[1]() print(numbers)
The sort() method arranges the list elements in ascending order.
Complete the code to find the middle element after sorting the list.
data = [7, 2, 9, 4, 5] data.sort() middle = data[[1]] print(middle)
Using len(data) // 2 gives the middle index for an odd-length sorted list.
Fix the error in the code to merge two sorted lists correctly.
list1 = [1, 3, 5] list2 = [2, 4, 6] merged = [] i = j = 0 while i < len(list1) and j < len(list2): if list1[i] < list2[[1]]: merged.append(list1[i]) i += 1 else: merged.append(list2[j]) j += 1 merged.extend(list1[i:]) merged.extend(list2[j:]) print(merged)
The comparison should be between list1[i] and list2[j] to merge correctly.
Fill both blanks to create a dictionary of word lengths for words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) as value and filters words with length greater than 3.
Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 letters.
words = ['tree', 'house', 'river', 'sky', 'mountain'] result = { [1]: [2] for word in words if len(word) [3] 4 } print(result)
The dictionary comprehension uses uppercase words as keys, their lengths as values, and filters words longer than 4 letters.
