Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/wp-content/themes/hworih/framework/admin/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 376

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/wp-content/themes/hworih/framework/admin/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 398

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/wp-content/themes/hworih/framework/admin/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 416

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/wp-content/themes/hworih/framework/admin/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 420

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/wp-content/themes/hworih/framework/admin/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 447

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/wp-content/themes/hworih/framework/admin/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 459

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/wp-content/themes/hworih/framework/admin/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 478
February 2016 – Eric Scrivner
Fixing Python’s title Function
home // page // Monthly Archives: February, 2016
Technical

Fixing Python’s title Function

Python’s title function has some weird side-effects when you’re titlizing a string like, for example, a street name: >>> "62nd".title() "62Nd" >>> "West 62nd st.".title() "West 62Nd St." Here’s how you can fix this: import re def fixed_title(input_string): parts = re.split(r'\s', input_string) for idx, value in enumerate(parts): if re.match(r'[A-Za-z]', value[0]): parts[idx] = value[0].upper() + value[1:] return ' '.join(parts) A simple fix that produces the right result: >>> fixed_title("West 62nd st.") "West 62nd St."