Complete the code to create a NumPy array from a list.
import numpy as np arr = np.array([1]) print(arr)
NumPy arrays are created from lists using np.array(). Lists are enclosed in square brackets.
Complete the code to access the third element of the NumPy array.
import numpy as np arr = np.array([10, 20, 30, 40, 50]) third_element = arr[[1]] print(third_element)
Indexing in Python starts at 0, so the third element is at index 2.
Fix the error in the code to correctly slice the first three elements of the array.
import numpy as np arr = np.array([5, 10, 15, 20, 25]) slice_arr = arr[[1]] print(slice_arr)
Slicing uses the colon : inside square brackets without extra brackets or commas.
Fill both blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 characters.
words = ['cat', 'elephant', 'dog', 'horse'] lengths = { [1] : [2] for word in words if len(word) > 3 } print(lengths)
The dictionary comprehension uses the word as the key and its length as the value.
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'] lengths = { [1] : [2] for word in words if len(word) [3] 3 } print(lengths)
The dictionary keys are uppercase words, values are their lengths, and the condition filters words longer than 3 characters.