Question: Python Let Ist be a list of integers. We define prefix_sum(i) to be the sum of the first (i+1) elements of Ist. That is: prefix_sum(i)

Python

Python Let Ist be a list of integers. We define prefix_sum(i) to

Let Ist be a list of integers. We define prefix_sum(i) to be the sum of the first (i+1) elements of Ist. That is: prefix_sum(i) Ist[01+Ist/1] + .sti. For example, if st [-1, 1, 4, -2,-31, . prefix_sum(0) is -1 prefix_sum(1) is 0, since (1) +10 . prefix_sum(2) is 4, since (-1)+1+4 4 . prefix_sum(3) is 2, since (1)+ 1+4 + (-2) 2 . prefix_sum(4) is -1, since (-1)+ 1+4+ (2)+ (-3)1 Complete the definition below for the function: def positive_prefix_sum(1st) This function is given a list of integers, lst. When called, it creates and returns a list with all the indices of which their prefix-sum is positive. For example, if lst- [-1, 1, 4, -2, -3], calling positive_prefix_sum(lst) should return [2, 31 Notes: 1. Your implementation should all be in the return line. That is, you are not allowed to add lines to this function, define an additional function, etc. 2. You may want to use the build-in sum function. 3. The indices should come in an ascending order. 4. In this question, don't worry about the runtime of your implementation. def positive_prefix_sum(lst): return

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!