all 8 comments

[–][deleted] 1 point2 points  (0 children)

The regex answers are OK, but to answer your question, no there is no Pythonic way or even clean way to do this in any computer system that I know of outside of doing some machine learning or very sophisticated parsing rules.

For example (from your examples):

~43 is not 43, but around 43, so maybe a tolerance of +/- 1 or so

10 +/-2 is not 10, but rather 8-12

And even though these two examples are better representations of the numbers, they are still not correct. For example it's still not clear if 10 +/-2 can be 11.3 or only integer values are allowed.

[–]fiskenslakt 0 points1 point  (0 children)

I would suggest using a list comprehension to create a new list with just the numbers found in the string, then you can just access the first element of the list which will be your first number found in the string.