nums = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} calc = lambda rom: sum((c := nums[s]) * (1, -1)[i != len(rom) - 1 and nums[rom[i + 1]] > c] for i, s in enumerate(rom)) compare_roman = lambda a, b : (a := calc(a)) > (b := calc(b)) or -(a < b)
nums = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}calc = lambda num: sum((-1 if e != len(num) - 1 and nums[num[e + 1]] > nums[x] else 1) * nums[x] for e,x in enumerate(num))compare_roman = lambda a, b : calc(a) > calc(b) or -(calc(a) < calc(b))#compare_roman = lambda a, b, calc=lambda num, nums={'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}: sum((-1 if e != len(num) - 1 and nums[num[e + 1]] > nums[x] else 1) * nums[x] for e,x in enumerate(num)): calc(a) > calc(b) or -(calc(a) < calc(b))#:)- nums = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
- calc = lambda rom: sum((c := nums[s]) * (1, -1)[i != len(rom) - 1 and nums[rom[i + 1]] > c] for i, s in enumerate(rom))
- compare_roman = lambda a, b : (a := calc(a)) > (b := calc(b)) or -(a < b)