Created
June 24, 2013 18:23
-
-
Save HugoPresents/5852246 to your computer and use it in GitHub Desktop.
Python upper to lower with underline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upper2lower(string): | |
string1 = '' | |
start = 0 | |
for m in re.finditer('[A-Z]', string): | |
if m.start() != 0: | |
string1 += string[start+1:m.start()] + '_' + m.group(0).lower() | |
else: | |
string1 += string[start:m.end()].lower() | |
start = m.start() | |
string1 += string[start+1:] | |
return string1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment