RosettaCodeData/Task/Roman-numerals-Decode/Python/roman-numerals-decode-3.py
2026-02-01 16:33:20 -08:00

4 lines
252 B
Python

from functools import reduce
numerals = { 'M' : 1000, 'D' : 500, 'C' : 100, 'L' : 50, 'X' : 10, 'V' : 5, 'I' : 1 }
def romannumeral2number(s):
return reduce(lambda x, y: -x + y if x < y else x + y, map(lambda x: numerals.get(x, 0), s.upper()))