def roman_to_int(roman):
    """
    https://gist.github.com/kristopherjohnson/f4eca9018c5085fc736b2f29a202b8f8
    """
    vals = {
        "I": 1,
        "V": 5,
        "X": 10,
        "L": 50,
        "C": 100,
        "D": 500,
        "M": 1000,
    }
    total = 0
    lastValue = sys.maxsize
    for char in list(roman):
        value = vals[char.upper()]
        if value > lastValue:
            total += value - 2 * lastValue
        else:
            total += value
        lastValue = value
    return total
def roman_to_int ( roman ) : vals = { "I" : 1 , "V" : 5 , "X" : 10 , "L" : 50 , "C" : 100 , "D" : 500 , "M" : 1000 , } total = 0 lastValue = sys . maxsize for char in list ( roman ) : value = vals [ char . upper ( ) ] if value > lastValue : total += value - 2 * lastValue else : total += value lastValue = value return total
https://gist.github.com/kristopherjohnson/f4eca9018c5085fc736b2f29a202b8f8