5

最初に、私は python を 2 日間使用し、さらに質問があります。そのうちの1つを下に。

私はリスト (3297 アイテム) を持っています。値 != '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

私は何を間違っていますか?

4

4 に答える 4