Romeinse cijfers

Thursday 18 November 2004, 13:54:00 | python

Convert integer to Roman number: (Courtesy of Andrea Griffini, on comp.lang.python)

roman = lambda x: "".join(["".join(map(lambda c: "IVXLCDM"[int(c) 
  +2*N],"/0/00/000/01/1/10/100/1000/02".split("/")[x//10**N % 10]))
  for N in (3, 2, 1, 0)])

Roman to integer: (Courtesy of titanstar on #python)

r2int = lambda s: s and [v+r2int(s[len(r):]) for r,v in [('M',1000),('CM',900),
  ('CD',400),('D',500),('C',100),('XC',90),('XL',40),('L',50),('X',10),
  ('IX',9),('IV',4),('V',5),('I',1)] if s.startswith(r)][0] or 0