Complete the code to reverse the list using the reversed() function.
numbers = [1, 2, 3, 4, 5] reversed_numbers = list([1](numbers)) print(reversed_numbers)
The reversed() function returns an iterator that accesses the given sequence in the reverse order. Wrapping it with list() converts it back to a list.
Complete the code to print each character of the string in reverse order using reversed().
word = "hello" for char in [1](word): print(char, end='')
The reversed() function can be used on strings to get an iterator that yields characters in reverse order.
Fix the error in the code to correctly reverse the tuple using reversed().
data = (10, 20, 30) reversed_data = [1](data) print(tuple(reversed_data))
The reversed() function works on tuples and returns an iterator. The reverse() method does not exist for tuples.
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = [1]: len(word) for word in words if len(word) [2] 3
The dictionary comprehension syntax requires curly braces and a colon. The condition filters words longer than 3 characters using '>'.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] result = [1]: [2] for word in words if len(word) [3] 3
The dictionary comprehension uses curly braces with uppercase words as keys and their lengths as values. The condition filters words longer than 3 characters using '>'.