Skip to Content

Gareth53.co.uk - the online home of Gareth Senior

Artist Names, from UPPERCASE to Lovely Case (Pt.2 Dealing With Roman Numerals)

6:46p.m., Tue 24 Jun 2008

A while back I wrote about converting the names of recording artists and bands from ALL UPPERCASE or, indeed, all lowercase into lovely Mixed Case (or STUDly CasE, as the case may be).

Original post is here...

Well, I got to write this code on a Hack Day we had last week. I wrote it in Python,as a learning experience mainly, and it was a great deal easier than I expected.

Back when I wrote my longhand auto-casing routine I conveniently ignored roman numeral cos it hurt my brain. Using Python's string methods I could easily detect whether a word was a roman numeral (within reason anyway).

the strip method (and it's brothers rstrip and lstrip) returns a copy of the string with the leading and trailing characters removed. The argument is a string specifying the set of characters to be removed. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped.

The count() method cam in handy too.

So, this conditional statement returns True for roman numerals upto and including 39.

((myWord.rstrip('ivx') == "") and (myWord.count('v') < 2) and (myWord.count('i') < 4) and (myWord.count('x') < 5))

You could include the "L" and "M" characters too (L = 50, M = 100) but then you'd have to test for words like "mix" and "mill" (and there's probably others). This would also improperly uppercase the band name "MILLI Vanilli. When you're dealing with names it's best to err on the side of caution.

Latest Posts

Blog Categories