Python: Super-Simple Roman Numeral -> Arabic

I just wrote this… it’s a very simple way to solve them. Yes, I know everybody’s done this… but mine takes, well, uh, no code. :smiley:

def roman2arabic(value):
    total = 0
    values = {
        'I': 1,
        'V': 5,
        'X': 10,
        'L': 50,
        'C': 100,
        'D': 500,
        'M': 1000
    }
    
    prevValue = 0
    for char in value:
        if values[char] > prevValue:
            total -= prevValue
        else:
            total += prevValue
        prevValue = values[char]
    total += prevValue
    
    return total

Just pass it a string… :slight_smile: