列表分配索引超出范围

时间:2019-05-01 23:35:19

标签: python python-3.x

我想在CodeSignal上放松一下,但是我明白了

"Traceback (most recent call last):
  main.py3
 in the pre-written template, in getUserOutputs
    userOutput = _runjpmds(testInputs[i])
  main.py3
 in the pre-written template, in _runjpmds
    return almostIncreasingSequence(*_fArgs_fnlehdkfpkip)
  main.py3
 on line 13, in almostIncreasingSequence
    del(newarr[i])
IndexError: list assignment index out of range

但是为什么?

def ifgood(arr):
for i in range(0, len(arr)-1):
    if arr[i+1] - arr[i] <= 0:
        return False
return True

def almostIncreasingSequence(sequence):
    if len(sequence) == 1:
        return True
    for i in range(0, len(sequence)):
        newarr = sequence
        del(newarr[i])
        if ifgood(newarr) == True:
            return True
    return False

0 个答案:

没有答案
相关问题