Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
5 lines - sub + split + eval solution in Clear category for Reveal the Number by kdim
from re import sub
def reveal_num(line: str) -> int | float | None:
sign = sub(r'\D*(\+|-).*', r'\1', '+' + line) # get last sign before digit
p1, *p2 = sub(r'[^0-9.]', r'', line).split('.') # split digits between dots
return eval(f'{sign}{p1}.{"".join(p2)}') if p1 or p2 else None # get result
Feb. 24, 2023
Comments: