在Python中使用枚举函数时,我只是简单地尝试引用前一项的值。我不知道语法,也无法在线找到它。非常感谢。感谢。
#if the close price is > line_price, and the previous is < line_price, then increment broken_line_count
mylist = [6000,6000,6000,6200,6200]
line_price = 6100
broken_line_count = 0
for i, x in enumerate(mylist):
if x>line_price and [i-1](x)<line_price:
broken_line_count +=1
print(broken_line_count)
显然[i-1](x)
不正确,这只是我想要实现的目的的说明。