I am trying to iterate over the input strings below. If I encounter a float or an int, I want to push the element to a stack. When I encounter an operator "+-/*" or parentheses "()" or an "=", I perform other operations. The trouble that I have is identifying the floats or ints. People have suggested regex to break these into a list of strings, but I still have the problem of identifying these items as a float or int. I've tried isinstance() and that doesn't work either.
inputs:
theInput1 = "3.2+.4*5.67/6.145="
theInput2 = "11.897/3.4+9.2-0.4*6.9/12.6-16.7="
theInput3 = "234+34*65="
theInput4 = "(12+3)*(56/2)/(34-4)="
Something that I have tried that didn't work. (I'm appending to a list to simulate pushing to a stack so that I don't have to cut/paste the entire stack class here.)
s = "3.2+.4*5.67/6.145="
list = []
for i in s:
if isinstance(i, float) == True or isinstance(i,int) == True:
list.append(i)
print(list)