For example, I need
listBuilder('24+3-65*2')
to return
['24', '+', '3', '-', '65', '*', '2']
We are not allowed to use custom imported functions. I have to make this work without them. This is what I have so far...
def listBuilder(expr):
operators = ['+', '-', '*', '/', '^']
result = []
temp = []
for i in range(len(expr)):
if expr[i] in operators:
result.append(expr[i])
elif isNumber(expr[i]): #isNumber() returns true if the string can convert to float
temp += expr[i]
if expr[i+1] in operators:
tempTwo = ''.join(temp)
result.append(tempTwo)
temp = []
tempTwo = []
elif expr[i+1] == None:
break
else:
continue
return result
At this point I am getting an error, string index out of range for the line including expr[i+1]
. Help would be much appreciated. I have been stuck on this for hours.