If I have data like this from a machine learning prediction:
print(prediction) is:
('blood_pressure', '0.99999046')
Then print(type(prediction)) is:
<class 'str'>
How do I convert this to a tuple?
If i do print(tuple(prediction)) this comes out like:
('(', "'", 'b', 'l', 'o', 'o', 'd', '_', 'p', 'r', 'e', 's', 's', 'u', 'r', 'e', "'", ',', ' ', "'", '0', '.', '9', '9', '9', '9', '9', '0', '4', '6', "'", ')')
>Solution :
You can use the builtin eval() function.
tuple_as_string = "('blood_pressure', '0.99999046')"
tuple_as_tuple = eval(tuple_as_string)
print(tuple_as_tuple)
print(type(tuple_as_tuple))