У меня есть программа Python для получения данных из файла JSON, а затем сохраните его в списке в порядке постфиксирования. Однако теперь я пытаюсь поместить данные в новый список, который находится в удобочитаемой математической нотации. Проблема в том, что я знаю, что мне нужно найти первого оператора, а затем найти предыдущие два числа - я могу сделать это для первого набора, однако рекурсия мимо этого пункта не работает, и я не могу понять, почему!Python Получить значения из списка в определенном порядке
testList = [None] * len(valueList)
global testListCounter
testListCounter = 0
def _solveProblem(i, testListCounter):
for i in range (len(typeList)):
if typeList[i] == "operation":
testList[testListCounter +1 ] = valueList[i]
_findLeftInteger(i)
i = i + 3
# _findRightInteger(i)
testListCounter = testListCounter + 3
return _solveProblem(i+1, testListCounter)
def _findLeftInteger(opPos):
for i in range(opPos, 0, -1):
if typeList[i-1] == ("constant") or typeList[i-1] == ("cell"):
testList[testListCounter] = valueList[opPos-1]
_findRightInteger(i-1)
def _findRightInteger(opPos):
for i in range(opPos, 0, -1):
if typeList[i-1] == ("constant") or typeList[i-1] == ("cell"):
testList[testListCounter+2] = valueList[opPos-1]
_solveProblem(0, testListCounter)
print (testList)
Valuelist содержит:
['2', '90', '/', 'pi', '100', 13604.5, '20', '90', '/', '*', '+', '100', '+', '+
', '+']
TypeList содержит:
['constant', 'constant', 'operation', 'function', 'constant', 'cell', 'constant'
, 'constant', 'operation', 'operation', 'operation', 'constant', 'operation', 'o
peration', 'operation']