Complete the code to perform a linear search for the target in the list.
def linear_search(lst, target): for i in range(len(lst)): if lst[i] == [1]: return i return -1
The code compares each element in the list to the target value to find its position.
Complete the code to perform a binary search on a sorted list.
def binary_search(lst, target): low = 0 high = len(lst) - 1 while low <= high: mid = (low + high) // 2 if lst[mid] == [1]: return mid elif lst[mid] < target: low = mid + 1 else: high = mid - 1 return -1
The binary search compares the middle element lst[mid] with the target to decide where to search next.
Fix the error in the binary search condition to correctly update the search range.
def binary_search(lst, target): low = 0 high = len(lst) - 1 while low <= high: mid = (low + high) // 2 if lst[mid] == target: return mid elif lst[mid] < target: low = mid + 1 else: high = [1] return -1
When the middle element is greater than the target, the search range's high index should move to mid - 1 to search the left half.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
lengths = {word: [1] for word in words if [2]The dictionary comprehension maps each word to its length using len(word), but only includes words where the length is greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is less than 5.
result = [1]: [2] for word in words if [3]
The comprehension maps each word converted to uppercase (word.upper()) to its length (len(word)), but only includes words shorter than 5 characters.