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 came 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
Muppets Birthday Card
5:47p.m., 28 Nov
Emma loves The Muppets. She even has her own Muppet who we call Emma Too and who was born at ...Detecting Online Status In The Browser
11:55a.m., 28 Nov
I was just heading into a meeting when I was asked how our (mostly web-based) iOS application was going to ...Dropping Support for Internet Explorer 6
2:37p.m., 11 Oct
Microsoft's Internet Explorer 6 has long been the bane of every front-end developer's life. It's a 10-year old browser - ...Xfm Buzz - A Radio Hack
1:15p.m., 31 May
At Global Towers we developers have 10% time to go away and hack at something that might, ultimately, bring value ...