Complete the code to sort the list in ascending order.
numbers = [5, 3, 8, 1] numbers.[1]() print(numbers)
The sort() method arranges the list items in ascending order.
Complete the code to reverse the order of the list.
letters = ['a', 'b', 'c', 'd'] letters.[1]() print(letters)
The reverse() method flips the order of the list items.
Fix the error in the code to sort the list in descending order.
scores = [70, 85, 90, 60] scores.sort([1]=True) print(scores)
The sort() method uses the reverse=True argument to sort descending. The blank should be the argument name reverse.
Fill both blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 letters.
words = ['cat', 'house', 'tree', 'a', 'dog'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) to get the length and filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 2 letters.
words = ['hi', 'hello', 'yes', 'no'] result = { [1]: [2] for w in words if len(w) [3] 2 } print(result)
The dictionary comprehension uses w.upper() as keys, len(w) as values, and filters words longer than 2 with >.