Question: im trying to make a stack data structure using python...
I'm trying to make a stack data structure using Python list. How can I break down a user input separated by spaces and store each one in a list? Also how do I make sure that the only valid inputs are positive numbers and the binary operators /, *, -, + . No negative numbers or letters.
For my push() function, I'm appending the user input into the list. I enter 1 3 + and I want it to put in 1, 3, and + separately into the list, not all together which I'm assuming is being read in as the string "1 3 +". I'm also assuming that when this gets split up, the list will become ['1', '3', '+']. I need the numbers to be converted to integers, but keep the '+' or any operators as a string and they will be stored in the stack. I am using Python 3, many thanks for the help.