Is there any way of removing single quotes from the beginning and the end of the output string or list? I tried replace("'",""), but that does not seem to work for certain reason.
The replace function worked while processing the input but I am puzzled why it does not work for the output.
For example, the code block below:
really_final_output = str(final_output).replace("'","")
return really_final_output
should generate something along the lines of:
1, 2, 3, 4, 5, 6, 7, 8, 9
instead of:
'1, 2, 3, 4, 5, 6, 7, 8, 9'
>Solution :
You simply can’t remove it because if you remove it from a string it won’t be a string anymore.
To get only the values you must string.split(‘,’) and you will get a list of all elements which can then be converted to integers or floats.
string = '1, 2, 3'
numbers = list(map(int, string.split(',')))
The argument passed to split() is the character on which you want to split.
Now, if you are trying to get say all numbers from keyboard input you can do something like this:
numbers = list(map(int, input("Input message: ").split()))
Here a good reference to practice and learn more about the string split method: https://www.w3schools.com/python/ref_string_split.asp