[Solved] How to convert a string containing “/” to a float in Python [duplicate]


>>> from __future__ import division
... 
... result = []
... text = "20 7/8 16 1/4"
... for num in text.split():
...     try:
...         numerator, denominator = (int(a) for a in num.split("https://stackoverflow.com/"))
...         result.append(numerator / denominator)
...     except ValueError:
...         result.append(int(num))
... 
>>> result
[20, 0.875, 16, 0.25]

2

solved How to convert a string containing “/” to a float in Python [duplicate]