Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
float if dot else int solution in Clear category for Reveal the Number by veky
def reveal_num(line: str) -> int | float | None:
sign, digits, dot = '+', [], ''
for c in line:
if c in '+-' and not digits: sign = c
elif c.isdecimal(): digits.append(c)
elif c == '.' and not dot: digits.append(dot := c)
if digits: return (float if dot else int)(sign + ''.join(digits))
Jan. 5, 2023
Comments: