Ad
Basic Language Features
Fundamentals
Control Flow
Code
Diff
  • from functools import reduce
    
    numbers= {1000:'M', 900:'CM',500:'D', 400:'CD', 100:'C', 90:'XC', 50:'L', 40:'XL', 10:'X', 9: 'IX', 5:'V', 4:'IV',1: 'I'}.items()
    
    def convert_decimal_roman(n: int):
        return reduce(lambda s,c: (s[0]%c[0],s[1]+c[1]*(s[0]//c[0])) ,numbers,(int(n),""))[1]
    • def convert_decimal_roman(number):
    • number = int(number)
    • str = ''
    • numDct = {1000: "M",
    • 900: "CM",
    • 500: "D",
    • 400: "CD",
    • 100: "C",
    • 90: "XC",
    • 50: "L",
    • 40: "XL",
    • 10: "X",
    • 9: "IX",
    • 5: "V",
    • 4: "IV",
    • 1: "I"}
    • for key, value in numDct.items():
    • str+= value * (number // key)
    • number %= key
    • return str
    • from functools import reduce
    • numbers= {1000:'M', 900:'CM',500:'D', 400:'CD', 100:'C', 90:'XC', 50:'L', 40:'XL', 10:'X', 9: 'IX', 5:'V', 4:'IV',1: 'I'}.items()
    • def convert_decimal_roman(n: int):
    • return reduce(lambda s,c: (s[0]%c[0],s[1]+c[1]*(s[0]//c[0])) ,numbers,(int(n),""))[1]