Question: Write a function named list_of_positive_indices takes 1 arguments, a list returns 1 value, a list In this function, you should loop through each element of

Write a function named list_of_positive_indices takes 1 arguments, a list returns 1 value, a list In this function, you should loop through each element of the argument list. If the element is positive, then you should append the index number of the positive element to a new list. If not, skip that index (i.e. do nothing). Once the loop is finished, return the new list. For example, list_of_positive_indices([1, -1, 0, 3]) should return [0, 3] . No imports! HINT: Instead of doing a simple for element in list: loop, try using the range() function in the loop header. Graded Read Only : import numpy as np np.random.seed(986) list1 = np.random.randint(-100, 100, 10) indices1 = np.arange(list1.shape[@])[listi > 0).tolist) pred1 = list_of_positive_indices(listi.tolist()) assert set (pred1) == set(indices1) : np.random.seed(578752) Read Only list2 = np.random.randint(-100, 100, 100) indices2 = np.arange(list2.shape[@])[list2 > 0).tolist() pred2 = list_of_positive_indices (list2.tolist) assert set(pred2) == set(indices2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
