checkmatch, 34, checkio, 59
I would like to give some feedback about ...
From: http://www.checkio.org/mission/currency-style/solve/
checkmatch, 34, checkio, 59: find_message("$5,34")
I believe my answer to be correct but am given a fail. It works on my local machine.
HTTP_USER_AGENT:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0 import re from string import maketrans class MatchError(AssertionError): pass def checkmatch(match): itable = ',.' otable = '.,' trantable = maketrans(itable, otable) original = str(match) try: match = match.lstrip('$') if match.endswith('.'): suffix = '.' elif match.endswith(','): suffix = ',' else: suffix = '' match = match.rstrip('.').rstrip(',') if match.count('.') > 1 and match.count(',') > 1: raise MatchError if match.find(',') != -1: if match.find('.') != 0: if match.find('.') < match.find(','): return '$' + match.translate(trantable) + suffix else: raise MatchError else: if len(match.split(',')[-1]) == 2: return '$' + match.translate(trantable) + suffix else: raise MatchError elif match.find('.') != -1: if len(match.split('.')[-1]) == 3: return '$' + match.translate(trantable) + suffix else: raise MatchError else: raise MatchError except MatchError: return original def checkio(format_string): pattern = re.compile(r'\$[0-9,.]*') matches = pattern.findall(format_string) matches = tuple([checkmatch(m) for m in matches]) format_string = pattern.sub('%s', format_string) return unicode(format_string %(matches), 'utf-8')