This is my solution in Python3
def remove_dollar(string: str) -> float: remove_char = string.replace('$', '' ).replace(' ', '') return float(remove_char)
EDIT: Removed space, thanks for correcting me guys
you alse need to remove space from the string to avoid the exception
This was great, but failed (Python 3.8) the first test due to the added space - added an additional replace and passed all tests.
def remove_dollar(string:str) -> float: remove_char = string.replace('$', '').replace(' ', '') return float(remove_char)
Thank you!
You could also use the method strip
strip
return float(string.strip("$"))
strip doc:
S.strip([chars]) -> str Return a copy of the string S with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead.
S.strip([chars]) -> str
Return a copy of the string S with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead.
This doesn't work with string = "-$ 0.1" isn't it? I'd rather prefer the replace way :P
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is my solution in Python3
EDIT: Removed space, thanks for correcting me guys
you alse need to remove space from the string to avoid the exception
This was great, but failed (Python 3.8) the first test due to the added space - added an additional replace and passed all tests.
Thank you!
You could also use the method
strip
strip
doc:This doesn't work with string = "-$ 0.1" isn't it? I'd rather prefer the replace way :P