Complete the code to get the first character of the string.
word = "hello" first_char = word[1]
The first character of a string is accessed using square brackets with index 0.
Complete the code to find the length of the string.
word = "hello" length = [1](word)
The len() function returns the number of characters in a string.
Fix the error in the code to get the last character of the string.
word = "hello" last_char = word[1]
Using index -1 accesses the last character of the string.
Fill both blanks to create a dictionary with words as keys and their lengths as values.
words = ["apple", "banana", "cherry"] lengths = {word[1] for word in words if len(word) [2] 5}
The dictionary comprehension uses word: len(word) to map words to their lengths, and filters words with length greater than 5.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, filtering words longer than 5.
words = ["apple", "banana", "cherry"] result = { [1]: [2] for word in words if len(word) [3] 5 }
The dictionary comprehension uses word.upper() as keys, len(word) as values, and filters words with length greater than 5.