Python, For Loop: How To Append The True Value[i] In The Next Cells[i+1,i+2,..] Until The Condition Become False
Could someone help with a logical scheme in for loop statement in Python? I try to be more clear: i want to build a for loop cycle where if a condition is TRUE i want to append the
Solution 1:
You can use a variable, here adding
, to both note that you have encountered condition 1, remember the value you got then, and also to see that you have not encountered condition 2 yet, so can keep adding it:
adding = None
for i in range(1,len(close)):
if first_condition():
adding = close.close[i]
list.append(adding) # i want to append close.close[i] for al the next cells i (i+1, i+2,...)
#until the SECOND condition become TRUE.
# SECOND CONDITION:
elif if (close.fast_ema[i-1] > close.int_ema[i-1] and close.fast_ema[i] > close.slow_ema[i]:
list.append(close.close)
adding = None
else:
if adding is not None:
list.append(adding)
else:
list.append(0)
Post a Comment for "Python, For Loop: How To Append The True Value[i] In The Next Cells[i+1,i+2,..] Until The Condition Become False"