一开始我用python 2天,问题比较多。下面是他们的一个。
我有一个列表(3297 个项目),我想从 value != 'nan' 的末尾找到第一个项目的索引
示例:(索引,值)
[0]  378.966
[1]  378.967
[2]  378.966
[3]  378.967
....
....
[3295]  777.436
[3296]  nan
[3297]  nan
如果想要找到具有索引的项目 - 3295
我的代码(从头到尾,一步一步)
    i = len(lasarr); #3297
    while (i >= 0):
            if not math.isnan(lasarr[i]):
                   method_end=i # i found !
                   break        # than exit from loop
            i=i-1 # next iteration
运行并得到错误
Traceback (most recent call last): File "./demo.py", line 37, in <module> if not math.isnan(lasarr[i]): IndexError: index out of bounds
我做错了什么?