I am trying to remove a value from the list but python seems to not be able to even though I am able to print it. The value is 5 which you will be able to see in the error but when I try to remove the same value it throws me an error message.
The "sequence.remove(e+1)
" line should be the same value as "print(sequence[e+1])
" right?
code:
def solution(sequence):
decisionList = []
ultDec = bool
def comparing():
i = 0
decisionList.clear()
for i in range(len(sequence)-1):
num1 = i
num2 = i + 1
if sequence[num1] < sequence[num2]:
decisionList.append("bigger")
if sequence[num1] > sequence[num2]:
decisionList.append("smaller")
if sequence[num1] == sequence[num2]:
decisionList.append("equal")
findIrregular()
repeated = 0
def findIrregular():
nonlocal repeated
ultDec = ""
e = 0
for e in range(len(decisionList)):
val1 = e
if decisionList[val1] == "smaller":
if repeated < 1:
print(sequence[e+1], "is the value im trying to remove")
sequence.remove(e+1)
repeated = repeated + 1
comparing()
if repeated >= 1:
return False
elif decisionList[val1] == "equal":
if repeated < 1:
sequence.remove(e + 1)
repeated = repeated + 1
comparing()
if repeated >= 1:
return False
elif decisionList[val1] == "bigger":
pass
return True
comparing()
return findIrregular()
solution([3, 6, 5, 8, 10, 20, 15])
error:
So as you can see "5 is the value im trying to remove
" is what causes the error
5 is the value im trying to remove
Traceback (most recent call last):
File "<string>", line 46, in <module>
File "<string>", line 44, in solution
File "<string>", line 16, in comparing
File "<string>", line 29, in findIrregular
ValueError: list.remove(x): x not in list