Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re.sub solution in Clear category for Currency Style by CDG.Axel
import re
def replacer(match: re.Match):
return match[0].translate(str.maketrans(',.', '.,'))
def checkio(line: str) -> str:
return re.sub(r'\$\d{1,3}(\.\d{3})*(,\d{2}){0,1}(?!\d)', replacer, line)
if __name__ == '__main__':
print("Example:")
print(checkio('$5.34'))
# These "asserts" are used for self-checking and not for an auto-testing
assert checkio('$5.34') == '$5.34'
assert checkio('$5,34') == '$5.34'
assert checkio('$222,100,455.34') == '$222,100,455.34'
assert checkio('$222.100.455,34') == '$222,100,455.34'
assert checkio('$222,100,455') == '$222,100,455'
assert checkio('$222.100.455') == '$222,100,455'
print("Coding complete? Click 'Check' to earn cool rewards!")
Oct. 25, 2021
Comments: