Complete the code to get the first element of the array.
import numpy as np arr = np.array([10, 20, 30, 40]) first_element = arr[[1]] print(first_element)
The first element in a Python array is accessed with index 0.
Complete the code to slice the array and get elements from index 1 to 4 (exclusive).
import numpy as np arr = np.array([5, 10, 15, 20, 25]) slice_arr = arr[[1]] print(slice_arr)
Slicing with 1:4 gets elements at indices 1, 2, and 3.
Fix the error in the code to correctly get the last two elements of the array.
import numpy as np arr = np.array([2, 4, 6, 8, 10]) last_two = arr[[1]] print(last_two)
Using -2: slices from the second last element to the end.
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 = ['cat', 'house', 'tree', 'a', 'elephant'] lengths = {word: [1] for word in words if [2] print(lengths)
Use len(word) to get length and filter words with length greater than 3.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, but only for words longer than 4 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] result = { [1]: [2] for w in words if [3] } print(result)
Keys are uppercase words, values are lengths, filtered by length > 4.