Skip to content

Instantly share code, notes, and snippets.

@HugoPresents
Created June 24, 2013 18:23
Show Gist options
  • Save HugoPresents/5852246 to your computer and use it in GitHub Desktop.
Save HugoPresents/5852246 to your computer and use it in GitHub Desktop.
Python upper to lower with underline
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