I have two functions, say
def f1(arr,k):
#does something here with elements of array arr starting from index k and returns i..
#EDIT: we don't need value1 from f1,
i=k
while arr[i]==0:
i=i+1
return i
and another function
def f2(arr,arr2,k):
# does something here with elements of array arr starting from index k (k is output from function f1)...
#EDIT: following is the code for f2:
pr=0
if arr[k]==1:
i=k
while (pr<10 and pr>-10) and (arr2[i+1]!=2):
pr=pr+(arr2[i+1]-arr2[i])
i=i+1
if arr[k]==2:
i=k
while (pr<10 and pr>-10) and (arr[i+1]!=1):
pr=pr+(arr2[i]-arr2[i+1])
i=i+1
return i+1, pr
This output i+1 is again used for function f1, we do this till the we reach the end of array.
I can't seem to get the logic on how to do this.
I define a function
def final(arr):
x=0 #starting index
#need to use above two functions to return value2 as a list for each iteration...
Can someone provide some direction?
EDIT: After doing what @AlexForGill answered, I am getting Index Out of Bounds error for function f2
def final(arr,arr2):
x=0
plist=[]
while x < len(arr)-1:
x = f1(arr, x)
if x >= len(arr)-1: # guard clause for applying second function
break
x, value2 = f2(arr,arr2, x)
plist.append(value2)
return plist
value1at all?f1inf2, and loop f2 iff1has nothing to do with the rest.