I have the following string:
str = "MMX Lions Television Inc"
And I need to convert it into:
conv_str = "2010 Lions Television Inc"
I have the following function to convert a roman numeral into its integer equivalent:
numeral_map = zip(
(1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
)
def roman_to_int(n):
n = unicode(n).upper()
i = result = 0
for integer, numeral in numeral_map:
while n[i:i + len(numeral)] == numeral:
result += integer
i += len(numeral)
return result
How would I use re.sub
to do the get the correct string here?
(Note: I tried using the regex
described here: How do you match only valid roman numerals with a regular expression? but it was not working.)