Complete the code to slice the array from index 1 to 5 (exclusive).
import numpy as np arr = np.array([10, 20, 30, 40, 50]) sliced = arr[[1]:5] print(sliced)
The slice 1:5 selects elements starting at index 1 up to but not including index 5.
Complete the code to slice the array to get every second element from the start to the end.
import numpy as np arr = np.array([5, 10, 15, 20, 25, 30]) sliced = arr[[1]] print(sliced)
The slice 0:6:2 starts at index 0, goes up to index 6 (exclusive), stepping by 2, selecting every second element.
Fix the error in the code to correctly slice the array backwards with step -1.
import numpy as np arr = np.array([1, 2, 3, 4, 5]) sliced = arr[[1]] print(sliced)
The slice ::-1 reverses the array by stepping backwards through all elements.
Fill both blanks to slice the array from index 2 to 8 (exclusive) with step 3.
import numpy as np arr = np.arange(10) sliced = arr[[1]:[2]:3] print(sliced)
The slice 2:8:3 starts at index 2, stops before index 8, stepping by 3.
Fill all three blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] lengths = { [1]: [2] for word in words if len(word) [3] 3 } print(lengths)
The dictionary comprehension syntax is {key: value for item in iterable if condition}. Here, keys are words, values are their lengths, and condition filters words longer than 3 letters.