Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Reverse Roman Numerals by flpo
import re
ROMANS = {
'I': 1,
'IV': 4,
'V': 5,
'IX': 9,
'X': 10,
'XL': 40,
'L': 50,
'XC': 90,
'C': 100,
'CD': 400,
'D': 500,
'CM': 900,
'M': 1000
}
sorted_keys = sorted(ROMANS, key=lambda k: -len(k))
def reverse_roman(roman):
return sum(ROMANS[k] for k in re.findall('|'.join(sorted_keys), roman))
July 5, 2017
Comments: