Artist Names, from UPPERCASE to Lovely Case (Pt.2 Dealing With Roman Numerals)
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).
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
Walking In Andorra
5:24p.m., 11 Jul
I've just returned from a week in Arinsal, Andorra. It's a popular ski resort, but almost the whole town seems ...A New Mix In The Cloud
5:27p.m., 30 May
I uploaded a new mix to mixcloud.com yesterday. The notion for the mix came from the grunge podcast we recorded ...League One Round-Up, Player Of The Year Awards 2009-2010
5:53p.m., 19 May
I've enjoyed this 2009/2010 football season. Huddersfield Town have managed to put together a young, hungry side with a smattering ...Wii Sports Resort Table Tennis - Tips To Beat Lucia
7:02p.m., 25 Apr
I love my Nintendo Wii. Partly it's because of the Wiimote, but mostly I love games that are simple to ...