Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Use mask for available chars solution in Clear category for Reveal the Number by U.V
def reveal_num(line: str) -> int | float | None:
sgn,numbr,point = '', '', False
mask = set('+-.0123456789') # Available chars for analysis
for c in line:
if c not in mask: continue
elif c in '+-':
numbr = c
continue
elif c.isdigit() : # Disable '+', '-'
mask.discard('+')
mask.discard('-')
elif c == '.':
mask.discard('.') # Disable '.'
point = True
numbr += c
return None if not numbr else float(numbr) if point else int(numbr)
Jan. 6, 2023
Comments: