I have the following problem. Suppose I have these two lists:
values = [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0] control = [0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0, 4.0, 4.0]
I now need a python code that does the following. It should copy the list values and then modify it based on the values of control.
-
If there is a 1 in the control list, then the value at the same position and the consecutive values in the new copied list should be reduced by one. For example, if there is a 1 at position 4 in the control list, then all values in the copied list from 4 to the last element should be reduced by one. If, for example, there is also a 1 at position 10, then all values from 10 to the end should also be reduced by one. In this case, all values from 4-9 are reduced by one in the copied list and then the values from 10 to the end are reduced by 2.
-
However, if there is a 0 at position i-1 in the copied list and a 1 at position i in the control list, then nothing should be decreased. It should therefore only continue to be reduced by one if the value i-1 >0. If this case is the first 1 in the control list, and then another 1 comes later, then from this point on it is reduced by 1 and not by two.
Here is an example for both cases:
1)
values = [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0] control =[0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 4.0, 4.0, 4.0] final = [0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 2.0, 2.0, 2.0]
2)
values = [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]
control =[0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0]
final = [0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0]