Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
13-liner: step by step solution in Clear category for Reveal the Number by przemyslaw.daniel
def reveal_num(line: str) -> int | float | None:
result, sign = "", ""
for char in line:
if char in "+-" and not result:
sign = char
if char == "." and "." not in result:
result += char
if char.isdecimal():
result += char
cast = float if "." in result else int
return cast(sign + result) if result else None
Jan. 8, 2023
Comments: