Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
What have the OrderedDicts ever done for us?! solution in Uncategorized category for Roman Numerals by smilicic
from collections import OrderedDict
ROMANS = OrderedDict([(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')])
def checkio(num):
roman_num = []
for roman_unit in ROMANS:
roman_count, num = divmod(num, roman_unit)
roman_num.append(ROMANS[roman_unit]*roman_count)
return ''.join(roman_num)
Dec. 23, 2016
Comments: