I'm working on a python script to convert full uppercase addresses to Title Case. The issue I'm facing is that when I apply .title()
to a string like SOUTH 16TH STREET, I get South 16Th Street. The desired conversion would be South 16th Street, where the abbreviation to the ordinal is lowercase.
What is a simple way in python to accomplish this? I was thinking about using some kind of regex.
It might be easiest to split the string into a list of separate words, capitalize each word and then join them back together:
The
capitalize()
method sets the first character of a string to uppercase and the proceeding characters to lowercase. Since numbers don't have upper/lowercase forms, "16TH" and similar tokens are transformed as required.